PyPI: pillow
CVE-2026-112898
Safety vulnerability ID: SFTY-20261021-59163
Affected versions of the Pillow package are vulnerable to Use of Uninitialized Variable due to a stack-allocated buffer being copied into a result without being fully populated. The `ImagingPaletteCacheUpdate()` function in `src/libImaging/Palette.c` declares a local `UINT8 c[512]` array that is only written inside a loop bounded by `palette->size`, but when `Image.quantize(palette=...)` is called with a zero-entry palette (producible via a PNG with an empty `PLTE` chunk, a colour-mapped TGA with a zero-length colour map, or a bare `Image.new("P", ...)`), the loop body never executes, leaving `c[]` uninitialized before it is copied into the colour cache and subsequently emitted as output pixel indices by `topalette()` in `src/libImaging/Convert.c`, since that function only rejects a `NULL` palette and not one with `size == 0`. An attacker who controls the palette image supplied to `Image.quantize(palette=...)` — for example through a palette-swap or pixel-art upload feature — can retrieve up to 512 bytes of the worker process's uninitialized stack memory encoded as pixel values in the returned image, potentially disclosing stack addresses, heap/libc/libpython pointers, and the stack-protector canary, which can aid in bypassing ASLR and stack protections in a long-lived server process.
Overview
Pillow: Image.quantize() with empty palette leaks uninitialized stack memory
Advisory
pillow – Use of Uninitialized Variable
How to Fix
Mitigation and Workarounds
---
Vulnerable Functions
Functions linked to known vulnerabilities.
References
- https://getsafety.com/vulnerabilities/SFTY-20261021-59163/CVE-2026-112898
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-rfgq-q3w2-pmv2
- https://nvd.nist.gov/vuln/detail/CVE-2026-112898
- https://github.com/python-pillow/Pillow/commit/13943c8f857b22f073d30f0ef9b725a0d255f1a4
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0
- https://github.com/advisories/GHSA-rfgq-q3w2-pmv2
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
