Pillow PDF rewriting flaw triggers infinite loops and service denial
A logic error in the Python imaging library allows crafted PDFs to lock workers in infinite cycles, risking denial of service for affected applications.

Key points
- The flaw exists in Pillow versions 5.1.0 through 12.x and is rated high severity with a CVSS score of 8.7.
- An attacker supplies a PDF with cyclic page tree relationships to trigger the bug during image appending operations.
- The issue is resolved in version 13.0.0, which introduces cycle detection in the page rewriting logic.
The Python imaging library Pillow contains a high-severity vulnerability that permits remote denial of service through crafted document inputs. Security researchers identified the issue in the library’s PDF handling routines, specifically within the page rewriting functionality. Applications that rely on Pillow to append images to PDF documents are exposed to this risk if they process untrusted files. The flaw allows an attacker to force a worker process into an infinite loop, consuming full CPU resources and effectively denying service to legitimate users.
Root cause
The underlying issue stems from how Pillow manages parent relationships within PDF page trees. According to the National Vulnerability Database, the PdfParser.rewrite_pages() method follows these relationships without detecting cycles. When a PDF contains a circular reference in its page structure, the parser enters an infinite loop. This behaviour is classified under CWE-835, which covers loops with unreachable exit conditions. The lack of cycle detection means the application cannot escape the recursive traversal, leading to a hung process that consumes maximum processor capacity.
Attack path
An adversary exploits this vulnerability by supplying a cyclic PDF file to a vulnerable application. The application must be configured to append an image to the provided PDF for the exploit to trigger. Once the application processes the file, the rewriting logic encounters the circular page tree reference. The worker thread then becomes trapped in the infinite loop, holding the CPU at full utilisation. This results in a denial of service condition, preventing the application from handling further requests or tasks.
Affected versions
The vulnerability affects Pillow versions ranging from 5.1.0 up to, but not including, 13.0.0. Any deployment running a version within this range is susceptible to the infinite loop condition when processing malicious PDF inputs. The issue is fixed in version 13.0.0, which includes the necessary cycle detection logic. Teams should verify their current Pillow version to determine if they fall within the affected range.
Mitigation
- Upgrade Pillow to version 13.0.0 or later to obtain the official fix for the cycle detection flaw.
- Validate PDF inputs for structural anomalies before passing them to Pillow for processing.
- Implement resource limits on worker processes to prevent single tasks from consuming all available CPU.
- Monitor application logs for unexpected hangs or excessive CPU usage during PDF processing tasks.
Signals worth monitoring
Security operations teams usually detect this activity by observing sustained high CPU utilisation on worker processes handling document uploads. Look for alerts indicating that specific threads are stuck in a loop or failing to complete tasks within expected timeframes. Check whether applications are logging errors related to PDF parsing timeouts or resource exhaustion. Containment moves typically involve isolating the affected worker pool and restarting services to restore capacity. Teams should also review recent upload volumes for anomalous file patterns that might indicate targeted abuse of the parsing logic.
What to do and how to stay safe: Pillow
- Audit your software bill of materials to identify any instances of Pillow versions earlier than 13.0.0.
- Apply the vendor-provided update to version 13.0.0 as soon as operational testing allows.
- Monitor system metrics for sudden spikes in CPU usage associated with image or PDF processing services.
- Restrict the types of files accepted by public-facing endpoints that utilise Pillow for document manipulation.
Step-by-step guide: Out-of-band patches: what small businesses need to know
General security guidance from the Firewall Pulse newsroom. It is not confirmed advice from the organisations named in this story.
Frequently asked questions
Which versions of Pillow are affected by CVE-2026-112406?
Versions 5.1.0 through 12.x are affected, while version 13.0.0 contains the fix.
What is the CVSS score for this vulnerability?
The National Vulnerability Database rates the severity as high with a CVSS score of 8.7.
How is the vulnerability triggered?
An attacker supplies a PDF with a cyclic page tree to an application that appends images to PDFs.



