GitHub advisory · PyPI
Pillow: Memory DoS in TIFF and EXIF IFD parsing via overlapping tag data
Description
============================================================================
ANT-2026-D7STJUWL [medium] CWE-770 dos
Memory DoS in TIFF and EXIF IFD parsing via overlapping tag data
Location: src/PIL/TiffImagePlugin.py:927 in ImageFileDirectory_v2.load()
Commit: a707c6b21c313880d0771e54965d142dd42358b6
============================================================================
A small, crafted image file can make Pillow use thousands of times its own size in memory while the file is only being opened, which lets anyone who can submit an image crash or stall the process handling it. A 144 KB TIFF makes Image.open() return normally while holding 1.6 GiB of memory. The largest such standard TIFF, about 786 KB, asks for roughly 48 GiB, which in practice gets the worker killed by the operating system. The file declares a 1×1 image, so the decompression-bomb check never triggers and no warning is raised. There is no memory corruption; the impact is denial of service.
The bug is in ImageFileDirectory_v2.load() in src/PIL/TiffImagePlugin.py (around line 927). For every directory entry whose value is stored elsewhere in the file, it reads that value into a new bytes object with ImageFile._safe_read(fp, count * unit_size) and keeps it in _tagdata. _safe_read() only checks that the bytes exist. Nothing limits the total read across entries, and nothing stops every entry from pointing at the same bytes. An attacker can therefore give each of N distinct private tags an offset and count that covers the whole file, at a cost of 12 bytes per entry. Memory grows as N × file size, which is quadratic in the file size, and BigTIFF removes the 65,535-entry ceiling.
The same loop parses EXIF data, so the problem reaches beyond TIFF:
Image.open() itself, via _read_dpi_from_exif().eXIf chunk costs 754 MiB on getexif() or ImageOps.exif_transpose().Manual fix · PyPI
pip install --upgrade "Pillow>=13.0.0"Sources