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.

Created at: Oct 22, 2026Updated at: Oct 22, 2026

Overview

Pillow: Quadratic-time DoS in PDF save_all (PdfParser.next_object_id)

Advisory

pillow – Inefficient Algorithmic Complexity

Affected Package

Affecting pillow package, versions>= 5.1.0, < 13.0.0

Also affects

---

How to Fix

Upgradepillowto13.0.0or higher.

Mitigation and Workarounds

---

Vulnerable Functions

Functions linked to known vulnerabilities.

Vulnerable function data is available for Enterprise customers

Book a call with us to see Safety in action.

Safety

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