PyPI: pillow
CVE-2026-112396
Safety vulnerability ID: SFTY-20261021-53359
Affected versions of the Pillow package are vulnerable to Use After Free due to improper cleanup when libtiff rejects a tag during TIFF encoding to an in-memory buffer. In `ImagingLibTiffEncode`, when `TIFFWriteScanline` fails, the function frees `clientstate->data` but leaves `clientstate->tiff` open and non-null, so subsequent teardown via `ImagingLibTiffEncodeCleanup` calls `TIFFClose`, which flushes buffered data through `_tiffWriteProc` and reallocs/memcpys into the already-freed buffer. An attacker can exploit this by supplying a crafted image with an invalid TIFF tag (such as Predictor=3 on integer sample data) that causes encoding to an in-memory target like `BytesIO` to fail, triggering a write into freed heap memory that can crash the process or potentially be leveraged for remote code execution.
Overview
Pillow: Heap use-after-free when encoding TIFF to an in-memory buffer
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-53359/CVE-2026-112396
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-4rr5-89j8-mwwm
- https://nvd.nist.gov/vuln/detail/CVE-2026-112396
- https://github.com/python-pillow/Pillow/commit/dc95da20207827a062cfbf551ee9f6031465a8bb
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0
- https://github.com/advisories/GHSA-4rr5-89j8-mwwm
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
