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

CVE-2026-96640: Pillow Python Library DOS Vulnerability

CVE-2026-96640 is a denial of service vulnerability in Pillow Python imaging library that allows attackers to cause excessive CPU consumption through malformed PDF files. This post covers technical details, affected versions, and mitigation.

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-96640 Overview

CVE-2026-96640 is a resource exhaustion vulnerability in Pillow, a widely used Python imaging library. The flaw resides in PdfParser.linearize_page_tree() within src/PIL/PdfParser.py. Affected versions span from 5.1.0 up to, but not including, 13.0.0. The parser treats a PDF /Pages graph as a tree without tracking duplicate indirect references. An attacker can supply a malformed PDF whose /Kids arrays repeatedly reference the same child /Pages node, causing exponential expansion during an append operation. The issue falls under [CWE-400] Uncontrolled Resource Consumption.

Critical Impact

A compact malformed PDF can generate exponentially many page references, consuming disproportionate CPU and causing denial of service in applications that call Image.save(..., format="PDF", append=True) on attacker-controlled input.

Affected Products

  • Pillow versions 5.1.0 through 12.x (prior to 13.0.0)
  • Python applications invoking Image.save() with format="PDF" and append=True on untrusted PDFs
  • Downstream services and document pipelines that embed Pillow for PDF generation

Discovery Timeline

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

Technical Details for CVE-2026-96640

Vulnerability Analysis

The vulnerability resides in Pillow's PDF append path. When Image.save() is called with format="PDF" and append=True, Pillow parses the existing PDF to merge new content. The linearize_page_tree() function in src/PIL/PdfParser.py walks the /Pages object graph recursively. PDF specifications permit indirect references, meaning multiple parents can point to the same child object. Pillow's walker treats each reference as a distinct subtree. A crafted PDF with /Kids arrays pointing at the same /Pages node at every level produces exponential growth: a document of a few kilobytes can expand to billions of logical page entries. The append operation stalls while consuming CPU, memory, and process time.

Root Cause

The root cause is missing duplicate-reference tracking during graph traversal. The parser assumed a tree structure where PDF semantics actually permit a directed acyclic graph with shared nodes. Without a visited-set guard, the recursion fans out combinatorially.

Attack Vector

Exploitation requires an attacker to deliver a malformed PDF to a service that passes it to Pillow with append=True. No authentication or user interaction is required beyond document submission. Common targets include document conversion APIs, print-to-PDF services, and automated report generators.

python
# Patch excerpt from src/PIL/PdfParser.py
# Fix: linearize_page_tree() now detects cycles and shared subtrees
         self.pages_ref = self.root[b"Pages"]
         assert self.pages_ref is not None
         self.page_tree_root = self.read_indirect(self.pages_ref)
-        self.pages = self.linearize_page_tree(self.page_tree_root)
+        self.pages = self.linearize_page_tree()
         # save the original list of page references
         # in case the user modifies, adds or deletes some pages
         # and we need to rewrite the pages and their list

Source: GitHub Pillow Commit 6f0e7ee. The patched function raises an error when a page loop is detected, preventing unbounded expansion.

Detection Methods for CVE-2026-96640

Indicators of Compromise

  • Python worker processes stuck at 100% CPU while handling PDF appends through Pillow
  • Unusually small inbound PDFs (a few KB) that trigger multi-minute or multi-hour processing times
  • Memory growth and process timeouts in services calling PdfParser.linearize_page_tree()

Detection Strategies

  • Inventory Python dependencies and flag any Pillow installations with versions >=5.1.0,<13.0.0
  • Add runtime timeouts around Image.save(..., format="PDF", append=True) and alert on repeated timeouts
  • Pre-validate uploaded PDFs by counting unique indirect object references in /Pages trees before passing to Pillow

Monitoring Recommendations

  • Collect per-request CPU and wall-clock metrics for document processing services and alert on outliers
  • Log PDF file size against processing duration to identify asymmetric workloads
  • Monitor container restarts and OOM-kill events on worker nodes handling user-supplied PDFs

How to Mitigate CVE-2026-96640

Immediate Actions Required

  • Upgrade Pillow to version 13.0.0 or later across all Python environments
  • Audit application code for Image.save() calls using format="PDF" and append=True on untrusted input
  • Enforce per-request CPU and wall-clock limits on document processing workers
  • Reject PDFs exceeding a reasonable logical page count after a pre-parse validation step

Patch Information

The fix is included in Pillow 13.0.0. See the GitHub Security Advisory GHSA-mrfp-p49p-3hf2, the Pillow Pull Request #10093, and the Pillow 13.0.0 Release Notes. The patched linearize_page_tree() raises an error when a cycle or duplicate reference is encountered during traversal.

Workarounds

  • Avoid calling Image.save() with append=True on PDFs sourced from untrusted users until upgrades are complete
  • Isolate Pillow PDF processing in a sandboxed worker with strict CPU and memory cgroup limits
  • Pre-screen incoming PDFs using a lightweight parser to reject documents with pathological /Pages structures
bash
# Upgrade Pillow to the patched release
pip install --upgrade "Pillow>=13.0.0"

# Verify the installed version
python -c "import PIL; print(PIL.__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.