PyPI: pillow
CVE-2026-112391
Safety vulnerability ID: SFTY-20261021-86543
Affected versions of the Pillow package are vulnerable to Loop with Unreachable Exit Condition ('Infinite Loop') due to an ineffective recursion-depth guard in `PdfParser.get_value()`. The `get_value()` classmethod accepts a `max_nesting` parameter that defaults to -1 and is decremented on every recursive call for nested arrays, dictionaries, and indirect object definitions, but its guard only checks for `max_nesting == 0`, a value that is never reached since the counter starts negative and only decreases further; this same unbounded recursion is also reachable through `linearize_page_tree()`. An attacker who supplies a crafted PDF file containing deeply nested objects (such as an array nested several thousand levels deep) can trigger this condition when the file is parsed via `PdfParser`, reachable through `Image.save(im, fp=<pdf>, format="PDF", append=True)` on an attacker-controlled PDF, causing an uncaught `RecursionError` that crashes the process and results in a Denial of Service.
Overview
Pillow: PdfParser can recurse without limit in get_value() and linearize_page_tree()
Advisory
pillow – Loop with Unreachable Exit Condition ('Infinite Loop')
How to Fix
Mitigation and Workarounds
---
Vulnerable Functions
Functions linked to known vulnerabilities.
References
- https://getsafety.com/vulnerabilities/SFTY-20261021-86543/CVE-2026-112391
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-254f-3936-288h
- https://nvd.nist.gov/vuln/detail/CVE-2026-112391
- https://github.com/python-pillow/Pillow/commit/94cb11c44ff7345414da17ebfea1598a529ad9cd
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0
- https://github.com/advisories/GHSA-254f-3936-288h
Verified by Safety
Our Cybersecurity Intelligence Team reviewed this vulnerability. We combine public data with our own research to find issues not yet reported to public sources.
Learn more
