VAITP Dataset

← Back to the dataset

CVE-2026-112406

Infinite loop in Pillow PDF rewrite allows DoS via cyclic PDF pages.

  • CVSS 8.7
  • CWE-835
  • Resource Management
  • Remote

Pillow is a Python imaging library. From 5.1.0 until 13.0.0, Pillow can enter an infinite loop while rewriting PDF pages. PdfParser.rewrite_pages() follows Parent relationships without detecting a cycle in the page tree. An attacker can supply a cyclic PDF to an application that appends an image to that PDF. This can hold the worker at full CPU and deny service. This issue is fixed in version 13.0.0.

CVSS base score
8.7
Published
2026-10-19
OWASP
A06 Vulnerable and Outdated Components
Orthogonal defect classification
Timing/Serialization
Code defect classification
Timing Issues
Category
Resource Management
Subcategory
Resource Exhaustion
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
Pillow
Fixed by upgrading
Yes

Solution

Upgrade Pillow to version 13.0.0 or later.

Vulnerable code sample

from PIL import PdfImagePlugin

def append_image_to_pdf(pdf_path: str, img_path: str) -> None:
    # Load the PDF and the image
    pdf = PdfImagePlugin.PdfParser(pdf_path)
    img = PdfImagePlugin.PdfImagePlugin().open(img_path)

    # Append the image as a new page (this triggers rewrite_pages)
    # VULNERABLE: rewrite_pages can loop forever on cyclic PDF page trees
    pdf.rewrite_pages()
    pdf.save(pdf_path, append_images=[img])

Patched code sample

from PIL import PdfImagePlugin

class FixedPdfParser(PdfImagePlugin.PdfParser):
    def rewrite_pages(self, _visited=None):
        if _visited is None:
            _visited = set()
        # FIX: detect cycles in the page tree to prevent infinite loops
        if id(self) in _visited:
            return  # break the cycle
        _visited.add(id(self))
        # Call the original implementation (assumed to be _rewrite_pages)
        super().rewrite_pages(_visited)

def append_image_to_pdf(pdf_path: str, img_path: str) -> None:
    # Load the PDF and the image
    pdf = FixedPdfParser(pdf_path)
    img = PdfImagePlugin.PdfImagePlugin().open(img_path)

    # Append the image as a new page (uses cycle‑aware rewrite)
    pdf.rewrite_pages()
    pdf.save(pdf_path, append_images=[img])

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

Cite this entry

@misc{vaitp:cve2026112406,
  title        = {{Infinite loop in Pillow PDF rewrite allows DoS via cyclic PDF pages.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-112406},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-112406/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.