CVE-2026-112895
Pillow PDF append parsing can cause recursive loops, leading to CPU/ memory exhaustion and DoS.
- CVSS 8.7
- CWE-674
- Resource Management
- Remote
Pillow is a Python imaging library. From 5.1.0 until 13.0.0, Pillow can exhaust resources while parsing an existing PDF during an append operation. PdfParser follows page-tree child references without cycle or duplication tracking and follows previous-trailer chains with only an exact repeated-offset guard, so deep or cyclic page trees and long chains of unique trailer offsets can exhaust the Python stack. Repeated non-cyclic /Kids references can also cause super-linear CPU and memory use. An attacker can supply such a PDF to an application that calls Image.save with PDF append enabled. This can raise an uncaught RecursionError or consume excessive CPU and memory before output is written, causing denial of service. This issue is fixed in version 13.0.0.
- CWE
- CWE-674
- CVSS base score
- 8.7
- Published
- 2026-10-19
- OWASP
- A04 Insecure Design
- Orthogonal defect classification
- Timing/Serialization
- Code defect classification
- Timing Issues
- Category
- Resource Management
- Subcategory
- Resource Exhaustion
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- Pillow
- Fixed by upgrading
- Yes
Solution
Upgrade Pillow to version 13.0.0 or newer.
Vulnerable code sample
from PIL import Image
def merge_pdf(source_path: str, target_path: str) -> None:
# VULNERABLE: unbounded recursion in Pillow PDF parser
img = Image.open(source_path)
img.save(target_path, format="PDF", append=True)Patched code sample
from PIL import Image
from PyPDF2 import PdfReader
def _has_cyclic_page_tree(pdf_path: str) -> bool:
try:
reader = PdfReader(pdf_path)
# Simple heuristic: if number of page objects exceeds a threshold,
# assume a malformed/cyclic structure that could trigger recursion.
return len(reader.pages) > 10000
except Exception:
return True
def merge_pdf(source_path: str, target_path: str) -> None:
# FIX: reject PDFs that could cause unbounded recursion
if _has_cyclic_page_tree(source_path):
raise ValueError("Unsafe PDF structure detected")
img = Image.open(source_path)
img.save(target_path, format="PDF", append=True)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.
- Walk PDF page tree iteratively (#10185) (python-pillow/Pillow)
src/PIL/PdfParser.py · PdfParser.linearize_page_tree
Cite this entry
@misc{vaitp:cve2026112895,
title = {{Pillow PDF append parsing can cause recursive loops, leading to CPU/ memory exhaustion and DoS.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-112895},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-112895/}}
}
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 ::
