CVE-2026-128067: Pillow libtiff Heap Buffer Overflow — One JPEG Leaks Your Server's Heap
What’s this?
Pillow 13.0.0 shipped on October 19, 2026 with a batch of security fixes. GHSA-xcvg-w56q-r89m caught my eye: a heap buffer overflow in the libtiff TIFF encoder, triggered when user-supplied EXIF metadata overrides geometry tags during image re-save. CVSS 4.0: 8.4 (High). The advisory mentioned out-of-bounds read and write, but no public PoC existed.
I built one. The result: upload a 204-byte JPEG, get 8,192 bytes of server heap in the TIFF that comes back. One HTTP POST, no credentials, 100% reliable.
PoC, detection rules, and live pcap: al4n4n/achilles-heel/CVE-2026-128067
The root cause
When Pillow saves an image as TIFF using the libtiff encoder, TiffImagePlugin._save sets geometry tags (ImageWidth, ImageLength, PlanarConfiguration) from the actual image dimensions. Then a merge loop overwrites them with whatever the caller passed via tiffinfo=, exif=, or the source image’s own IFD. SamplesPerPixel is never explicitly set for single-band modes.
The row buffer is allocated from the real image: for a 64x64 grayscale image, that’s calloc(64, 1) = 64 bytes. But TIFFWriteScanline reads a scanline sized by the tag-described geometry. With SamplesPerPixel=3 injected through EXIF, libtiff reads 192-byte scanlines from a 64-byte buffer.
The extra 128 bytes per row come from whatever sits behind the buffer on the heap. And because the output TIFF is returned to the caller, those bytes go straight back to the attacker.
Three impacts
The PoC demonstrates three variants from a single attack surface:
Heap data leak. EXIF SamplesPerPixel=3, Photometric=RGB makes the encoder read 192-byte rows from a 64-byte buffer. 128 bytes of heap per row × 64 rows = 8,192 bytes of server memory per request, returned in a valid TIFF image.
Heap write. Adding Predictor=2 to the EXIF makes libtiff apply horizontal differencing to each row before compression. On libtiff < 4.7.1, horDiff8 differences the row in place — rewriting the 128 heap bytes past the buffer on every row. On libtiff 4.7.1+ (official Pillow wheels), it works on a private copy, so Predictor=2 is only an additional over-read.
Crash. EXIF ImageWidth=134217728 (128 MiB) makes libtiff attempt a 128 MiB scanline read from a 64-byte buffer. Instant SIGSEGV.
The information disclosure angle
The leak variant is the most interesting. The attacker sends one HTTP POST with a 204-byte JPEG and gets a TIFF containing 8 KB of the target’s heap. The leaked data contains heap metadata, pointer-like values from mmap’d regions, and whatever data structures the allocator placed adjacent to the encoder’s buffer.
This is not a crash — the server returns HTTP 200 with a valid TIFF. It works on every request. It requires no credentials. And the leaked data changes between requests as the heap layout shifts.
ASAN confirms
I built Pillow and libtiff 4.7.0 with AddressSanitizer to get the exact trace:
1 | ==8==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x506000001ce0 |
The buffer is allocated at encode.c:293 (64 bytes for the 64-pixel row). The overflow starts at the very first byte past it — tif_lzw.c:1163 in LZWEncode.
The vulnerable pattern
The app doesn’t have to do anything exotic. This is the vulnerable code:
1 |
|
The key line is exif=img.getexif() — it passes the attacker’s EXIF metadata through to the TIFF encoder, where the geometry tags override the buffer dimensions.
The fix
Pillow 13.0.0 added a check in ImagingLibTiffEncode that compares TIFFScanlineSize64() against state->bytes before writing any scanlines. If the tag-described scanline is larger than the buffer, it returns “encoder error -8” instead of proceeding.
Fix commit: ec5f1cb
Reliability
10-round test against the distro build (Pillow 12.3.0, libtiff 4.7.0):
- leak: 10/10
- write: 10/10
- crash: 10/10
All three variants fire on every single request.
What to do
Upgrade to Pillow 13.0.0:
1 | pip install --upgrade pillow |
If you’re on any version from 2.3.0 through 12.3.0 and your application passes user-supplied metadata to the TIFF encoder, you’re vulnerable.
Reproduce it
1 | git clone https://github.com/al4n4n/achilles-heel.git |
References
- GHSA-xcvg-w56q-r89m (GitHub Security Advisory)
- CVE-2026-128067
- Fix commit ec5f1cb
- Pillow 13.0.0 release notes