Skip to content
Pillow PDF Append Flaw Triggers RecursionError in Python Services
Vulnerabilities

Pillow PDF Append Flaw Triggers RecursionError in Python Services

A high-severity vulnerability in Pillow allows crafted PDFs to exhaust resources during append operations, risking denial of service for affected Python applications.

Key points

  • CVE-2026-112895 affects Pillow versions 5.1.0 through 12.9.9
  • The flaw enables resource exhaustion via cyclic page trees or trailer chains
  • Version 13.0.0 resolves the issue by adding cycle and depth tracking

Pillow, the widely used Python imaging library, contains a high-severity vulnerability that allows attackers to trigger denial of service. The flaw exists in the PDF parsing logic used during append operations.

What happened

The National Vulnerability Database records CVE-2026-112895 as a high-severity issue with a CVSS score of 8.7. The vulnerability affects Pillow versions starting from 5.1.0 up to, but not including, 13.0.0. According to the NVD record, the flaw stems from how `PdfParser` handles existing PDF files during an append operation.

The parser follows page-tree child references without tracking cycles or duplications. It also follows previous-trailer chains using only an exact repeated-offset guard. This design allows deep or cyclic page trees to exhaust the Python stack. Long chains of unique trailer offsets can similarly cause resource exhaustion.

Repeated non-cyclic `/Kids` references can also cause super-linear CPU and memory usage. An attacker can supply a malicious PDF to an application that calls `Image.save` with PDF append enabled. This input can raise an uncaught `RecursionError` or consume excessive resources before output is written.

Why it matters

GitHub advisory GHSA-p4wg-p73j-c528 details that two recursive parsers lack effective bounds. The `linearize_page_tree` function follows `/Kids` without a visited set or depth limit. A cyclic or duplicated page tree recurses without end.

The `read_prev_trailer` function rejects only an exactly repeated `/Prev` offset. A long chain of unique offsets slips past this check. The trailer-loop guard added for CVE-2026-42310 does not cover these specific cases.

A service that appends to user-supplied PDFs is exposed to this risk. The issue is fixed in version 13.0.0. Applications using older versions remain vulnerable to stack exhaustion and resource consumption.

What to watch

  • Monitor for `RecursionError` exceptions in logs related to PDF processing
  • Check for unusual CPU or memory spikes during file append operations
  • Verify that Pillow versions are updated to 13.0.0 or later
  • Inspect input validation for PDF files before processing

Signals worth monitoring

Security teams should look for sudden spikes in memory consumption or CPU usage when services process PDF files. Logs may show repeated recursion errors or stack overflow messages from the Python interpreter. Unusual latency in file handling operations can also indicate resource exhaustion. Teams usually check whether input validation is in place for file uploads. Containment moves often involve restricting file types or limiting the size of uploaded documents. Monitoring for unexpected process terminations can help identify affected services quickly.

Background: CVSS score

CVSS provides a standardized vector for exploit difficulty and access requirements, not business value. A high score indicates an easy attack path, not necessarily significant damage. You must contextualize the score with your environment’s exposure, asset value, and compensating controls to determine true risk.

Read the full guide: CVSS Scores: Why High Numbers Mislead Your Risk Assessment

What to do and how to stay safe: Pillow

  • Update Pillow to version 13.0.0 or later to resolve the vulnerability
  • Implement input validation to reject malformed or suspicious PDF files
  • Set resource limits on processes that handle PDF append operations
  • Monitor application logs for recursion errors or resource exhaustion

General security guidance from the Firewall Chronicle 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-112895?

Versions from 5.1.0 up to, but not including, 13.0.0 are vulnerable.

What is the CVSS score for this vulnerability?

The National Vulnerability Database rates it as 8.7, which is high severity.

Is there a fix available for this issue?

Yes, the issue is fixed in Pillow version 13.0.0.

Sources

  1. CVE Program
  2. GitHub Advisory Database

Related stories

Pillow Rank Filter Crash in Zero-Size Images Fixed in 13.0.0

A high-severity flaw in older Pillow versions causes native crashes when processing zero-size images with rank-based filters, resolved in the latest release.