Skip to main content
Vulnerability Database/CVE-2026-113786

CVE-2026-113786: pypdf Library Image Parser Vulnerability

CVE-2026-113786 is an image parser vulnerability in pypdf, a pure-python PDF library, that allows attackers to trigger unintended image parsers through crafted PDFs. This post explains its impact, affected versions, and mitigation steps.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-113786 Overview

CVE-2026-113786 affects pypdf, a free and open-source pure-Python PDF library. Versions prior to 6.21.1 allow an attacker to 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. The maintainers addressed the issue in pypdf 6.21.1 by constraining Pillow to the JPEG format when decoding /DCTDecode streams. The weakness is categorized as improper input validation [CWE-20].

Critical Impact

A malicious PDF can coerce Pillow into invoking an unintended image parser, enabling limited availability impact when applications process attacker-supplied documents.

Affected Products

  • pypdf versions prior to 6.21.1
  • Python applications using pypdf with the optional Pillow dependency installed
  • Document processing pipelines invoking pypdf image extraction on untrusted PDFs

Discovery Timeline

  • 2026-10-21 - CVE-2026-113786 published to NVD
  • 2026-10-22 - Last updated in NVD database

Technical Details for CVE-2026-113786

Vulnerability Analysis

The flaw resides in pypdf's image extraction path in pypdf/generic/_image_xobject.py. When pypdf encountered an image XObject whose last filter was /DCTDecode, it passed the raw bytes to PIL.Image.open() without restricting the acceptable image formats. Pillow then performed its own format sniffing against the byte stream, which could select a parser other than JPEG. A crafted PDF therefore controls which Pillow codec is invoked, routing attacker-supplied bytes into an unintended decoder.

Root Cause

The root cause is improper input validation of the image data associated with the /DCTDecode filter. pypdf trusted the filter label to describe the payload format and did not pin Pillow to the JPEG plugin. Pillow's Image.open() falls back to magic-byte sniffing when the formats argument is omitted, allowing a mismatched decoder to process the bytes.

Attack Vector

Exploitation requires an application to load a malicious PDF through pypdf with Pillow installed and extract or render embedded images. User interaction is required, since a victim must open or process the crafted document. The impact is limited to availability, consistent with the low CVSS rating.

python
            )
            img = _image_from_bytes(fallback_mode, size, fallback_data)
    elif last_filter == FT.DCT_DECODE:
-       img, image_format, extension = Image.open(BytesIO(data)), "JPEG", ".jpg"
+       img, image_format, extension = Image.open(BytesIO(data), formats=("JPEG",)), "JPEG", ".jpg"
        # invert_color kept unchanged
    elif last_filter == FT.JPX_DECODE:
        img, image_format, extension, invert_color = _handle_jpx(

Source: GitHub Commit 512d8eb. The patch passes formats=("JPEG",) to Image.open(), forcing Pillow to use only the JPEG plugin when the /DCTDecode filter is present.

Detection Methods for CVE-2026-113786

Indicators of Compromise

  • PDF files whose image XObjects declare the /DCTDecode filter but contain non-JPEG magic bytes such as PNG, GIF, BMP, or TIFF headers.
  • Unexpected Pillow decoder exceptions or crashes originating from pypdf/generic/_image_xobject.py during document processing.
  • Elevated memory or CPU usage from Python worker processes decoding user-submitted PDFs.

Detection Strategies

  • Inventory Python environments to identify installations of pypdf below 6.21.1 that also include Pillow.
  • Instrument document ingestion services to log the pypdf version, Pillow version, and filename for every parsed PDF.
  • Scan stored PDFs for /DCTDecode filter dictionaries whose stream contents do not begin with the JPEG FFD8FF marker.

Monitoring Recommendations

  • Alert on repeated Pillow UnidentifiedImageError or decoder exceptions tied to PDF ingestion workers.
  • Monitor crash loops, restarts, or OOM kills in services that parse user-uploaded PDFs.
  • Track outbound dependency updates in CI to confirm pypdf 6.21.1 or later is deployed across all services.

How to Mitigate CVE-2026-113786

Immediate Actions Required

  • Upgrade pypdf to version 6.21.1 or later across all applications and container images.
  • Rebuild and redeploy Python services that embed pypdf as a transitive dependency.
  • Validate PDF ingestion pipelines in a sandboxed environment before returning to production processing.

Patch Information

The fix is included in pypdf 6.21.1 and merged via Pull Request #4222. Full technical context is available in the GHSA-5hx5-vpf9-5wcv advisory. The patch restricts PIL.Image.open() to the JPEG plugin when decoding /DCTDecode streams.

Workarounds

  • Uninstall the optional Pillow dependency where image extraction is not required, since environments without Pillow are not affected.
  • Process untrusted PDFs inside isolated containers or sandboxes with constrained CPU and memory limits.
  • Pre-filter uploaded PDFs to reject documents whose /DCTDecode streams lack a valid JPEG FFD8FF signature.
bash
# Upgrade pypdf to the patched release
pip install --upgrade "pypdf>=6.21.1"

# Verify the installed version
python -c "import pypdf; print(pypdf.__version__)"

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.