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.

Created at: Oct 27, 2026Updated at: Oct 27, 2026

Overview

Pillow: Infinite loop in PdfParser.rewrite_pages on page tree Parent cycle

Advisory

pillow – Loop with Unreachable Exit Condition ('Infinite Loop')

Affected Package

Affecting pillow package, versions>= 5.1.0, < 13.0.0

Also affects

---

How to Fix

Upgradepillowto13.0.0or higher.

Mitigation and Workarounds

---

Vulnerable Functions

Functions linked to known vulnerabilities.

Vulnerable function data is available for Enterprise customers

Book a call with us to see Safety in action.

Safety

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