CVE-2026-112895 (GHSA-p4wg-p73j-c528, CWE-674) is an uncontrolled-recursion / resource-exhaustion flaw in Pillow's PDF parser that is reachable whenever an application calls Image.save(..., format="PDF", append=True) on an attacker-supplied PDF. Parsing the existing file happens inside PdfParser.__init__ -> read_pdf_info() -> read_trailer() and the page-tree linearization. Two recursive routines had no effective bound, so malicious input can exhaust the Python call stack (or cause super-linear CPU/memory work) before any output is produced.
-
PdfParser.linearize_page_tree (src/PIL/PdfParser.py) — the function patched by the referenced commit e2ae7eac ("Walk PDF page tree iteratively (#10185)"). It walked the /Pages -> /Kids tree with one recursive call per level (pages.extend(self.linearize_page_tree(kid_object, processed_ids))). A deeply nested or cyclic page tree recurses until RecursionError. The fix converts the recursion into an explicit stack of iterators (stack = [iter(page_node[b"Kids"])] ... stack.append(iter(kid_object[b"Kids"]))), exactly because "a deep page tree cannot exhaust the call stack". This is the primary vulnerable function and its frames dominate the traceback for the cyclic/deep page-tree PoC in the advisory.
-
PdfParser.read_prev_trailer (src/PIL/PdfParser.py) — the second unbounded parser explicitly named in the CVE title ("...page tree or trailer chain") and advisory. It recursively followed the /Prev trailer chain and only rejected an exactly repeated offset (the processed_offsets check added for CVE-2026-42310). A chain of many distinct trailer offsets therefore still recursed without bound and exhausted the stack; it was made iterative (while-loop) in the same 13.0.0 release cycle (commit 852d834, #10023 "Use while loop in read_prev_trailer() to avoid RecursionError"). It is the routine whose frames appear for the trailer-chain variant of the DoS.
Both are plain Python methods on the PdfParser class, so a Python profiler/stack trace shows them as PdfParser.linearize_page_tree and PdfParser.read_prev_trailer. Any service that appends to user-supplied PDFs (stamping/watermarking pipelines) is exposed; upgrading to Pillow 13.0.0 removes both unbounded recursions.