PyPI: pillow
CVE-2026-112402
Safety vulnerability ID: SFTY-20261021-43268
Affected versions of the Pillow package are vulnerable to Use After Free (CWE-416) due to `ImagingScaleAffine()` deleting an `Imaging` structure it does not own when its internal allocation fails. When `calloc()` for the per-column lookup table fails inside `ImagingScaleAffine()` in `src/libImaging/Geometry.c`, the function calls `ImagingDelete(imOut)` even though, when reached via `Image.transform()`, `imOut` is the struct backing a live Python `ImagingCore` object; `_dealloc()` in `src/_imaging.c` subsequently calls `ImagingDelete()` on the same struct again, writing to and freeing already-freed memory. An attacker who can control the output size passed to `Image.transform()` (via `Transform.EXTENT` or `Transform.AFFINE` with a pure scale/translate matrix and default NEAREST resampling) can request a very wide, single-row output so that the output image allocates successfully while the larger lookup table allocation fails, triggering the double free and crashing the worker process with corrupted heap state, which is especially reachable on workers constrained by an address-space limit (`ulimit -v`, `uwsgi --limit-as`, `systemd LimitAS=`) or on 32-bit processes.
Overview
Pillow: Double free in ImagingScaleAffine on calloc failure via Image.transform
Advisory
pillow – Use After Free
How to Fix
Mitigation and Workarounds
---
Vulnerable Functions
Functions linked to known vulnerabilities.
References
- https://getsafety.com/vulnerabilities/SFTY-20261021-43268/CVE-2026-112402
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-7mwm-ghpf-9vrm
- https://nvd.nist.gov/vuln/detail/CVE-2026-112402
- https://github.com/python-pillow/Pillow/commit/aafa6c75f7cdabb9f409a8aac7c780bea31d08d9
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0
- https://github.com/advisories/GHSA-7mwm-ghpf-9vrm
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
