PyPI: pillow
CVE-2026-112406
Safety vulnerability ID: SFTY-20261021-82408
Affected versions of the Pillow package are vulnerable to Infinite Loop due to an unbounded upward traversal of the PDF page tree. The `PdfParser.rewrite_pages()` method, specifically the `while pages_tree_node_ref:` loop at `src/PIL/PdfParser.py:505`, walks each page's `/Parent` chain upward until it encounters a node without a `/Parent` entry, but it keeps no record of previously visited nodes, so a cycle in the chain (for example, a `/Pages` root whose `/Parent` points back to itself) causes the loop to never terminate. An attacker can craft a small, malformed PDF in which a page-tree node's `/Parent` reference forms a cycle, and when an application calls `im.save(fp, "PDF", append=True)` on that file via `PdfImagePlugin._save()` and `write_catalog()`, the worker thread or process enters an endless loop consuming 100% of a CPU core, resulting in a Denial of Service that only an external timeout can interrupt.
Overview
Pillow: Infinite loop in PdfParser.rewrite_pages on page tree Parent cycle
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-82408/CVE-2026-112406
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-f2g6-542v-9j58
- https://nvd.nist.gov/vuln/detail/CVE-2026-112406
- https://github.com/python-pillow/Pillow/commit/b3ebf20c694f2f12537a629c30229a1d5a53f777
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0
- https://github.com/advisories/GHSA-f2g6-542v-9j58
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
