CVE-2026-113786
pypdf < 6.21.1 allows crafted DCTDecode images to trigger wrong Pillow parser.
- CVSS 2.3
- CWE-20
- Input Validation and Sanitization
- Remote
pypdf is a free and open-source pure-python PDF library. Prior to 6.21.1, an attacker can craft a PDF containing image data labeled with the /DCTDecode filter that causes Pillow to select and invoke an unintended image parser when the image is loaded. Environments without the optional Pillow dependency are not affected. This issue is fixed in version 6.21.1.
- CWE
- CWE-20
- CVSS base score
- 2.3
- Published
- 2026-10-21
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Interface
- Code defect classification
- Incorrect Interface
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- pypdf
- Fixed by upgrading
- Yes
Solution
Upgrade pypdf to version 6.21.1 or later.
Vulnerable code sample
import sys
from io import BytesIO
from pypdf import PdfReader
from PIL import Image
def extract_first_image(pdf_path: str) -> Image.Image:
reader = PdfReader(pdf_path)
for page in reader.pages:
if "/XObject" in page["/Resources"]:
xobjects = page["/Resources"]["/XObject"].get_object()
for obj in xobjects.values():
if obj["/Subtype"] == "/Image" and obj["/Filter"] == "/DCTDecode":
# VULNERABLE: unsafe parser selection allows unintended image parser
raw = obj.get_data()
return Image.open(BytesIO(raw))
raise ValueError("No DCTDecode image found")Patched code sample
import sys
from io import BytesIO
from pypdf import PdfReader
from PIL import Image
def extract_first_image(pdf_path: str) -> Image.Image:
reader = PdfReader(pdf_path)
for page in reader.pages:
if "/XObject" in page["/Resources"]:
xobjects = page["/Resources"]["/XObject"].get_object()
for obj in xobjects.values():
if obj["/Subtype"] == "/Image" and obj["/Filter"] == "/DCTDecode":
# FIX: enforce JPEG format to prevent unintended parser use
raw = obj.get_data()
img = Image.open(BytesIO(raw))
if img.format != "JPEG":
raise ValueError("Unexpected image format")
return img
raise ValueError("No DCTDecode image found")Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- SEC: Only open /DCTDecode image data with the Pillow JPEG plugin (#4222) (py-pdf/pypdf)
pypdf/generic/_image_xobject.py · _xobj_to_image
Cite this entry
@misc{vaitp:cve2026113786,
title = {{pypdf < 6.21.1 allows crafted DCTDecode images to trigger wrong Pillow parser.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-113786},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-113786/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
