PyPI: pillow
CVE-2026-112894
Safety vulnerability ID: SFTY-20261021-17221
Affected versions of the Pillow package are vulnerable to Inefficient Algorithmic Complexity due to the PDF writer recomputing the full set of reserved object ids on every allocation instead of tracking the highest id incrementally. The `PdfParser.next_object_id` method calls `XrefTable.keys()`, which rebuilds three sets covering all previously reserved ids and then computes `max()` over the result, and `PdfImagePlugin._save()` invokes this method three or four times per frame before writing any page, making the per-frame id reservation loop O(N²) in the number of frames, with `n_frames` taken directly from file metadata (such as an APNG `acTL` chunk) before any frame is actually decoded. An attacker can exploit this by submitting a crafted multi-frame image, such as a GIF with tens of thousands of trivial frames or a tiny APNG that merely declares a large frame count, to any application that converts uploaded images to PDF via `im.save(..., "PDF", save_all=True)`, causing a worker thread to consume full CPU for minutes with a sub-megabyte file and resulting in Denial of Service without requiring unusual memory consumption or triggering existing decompression-bomb protections.
Overview
Pillow: Quadratic-time DoS in PDF save_all (PdfParser.next_object_id)
Advisory
pillow – Inefficient Algorithmic Complexity
How to Fix
Mitigation and Workarounds
---
Vulnerable Functions
Functions linked to known vulnerabilities.
References
- https://getsafety.com/vulnerabilities/SFTY-20261021-17221/CVE-2026-112894
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-jg86-v3jv-hrpm
- https://nvd.nist.gov/vuln/detail/CVE-2026-112894
- https://github.com/python-pillow/Pillow/commit/f6a852555f1a1bdff7781abf25f1a3b8bd6ce6cb
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0
- https://github.com/advisories/GHSA-jg86-v3jv-hrpm
Verified by Safety
Our Cybersecurity Intelligence Team reviewed this vulnerability. We combine public data with our own research to find issues not yet reported to public sources.
Learn more
