Pillow multi-frame loaders can reuse stale native image storage after mode transitions
Summary
Pillow multi-frame image loaders can retain native ImagingCore storage allocated for one frame while changing the Python-side image mode and decoder tiles for a later frame.
If frame 0 allocates storage for a narrow mode such as L, and a later frame of the same dimensions switches to a wider mode such as RGB or CMYK, Pillow may decode wider pixels into the stale narrow native buffer. This causes native out-of-bounds writes and process crashes. In the MPO/JPEG path, command execution was also demonstrated in matching Python/Pillow runtime profiles through Pillow's documented ImageSequence.Iterator + frame.load() path.
Details
The root cause appears to be that ImageFile.load_prepare() only reallocates native storage when _im is None. It does not verify that the retained native ImagingCore storage still matches self.mode and self.size.
Several multi-frame seek() / _open() paths can update self._mode and decoder tiles for a later frame without invalidating _im. The decoder then writes or reads according to the new frame mode while the native storage still belongs to the old frame mode.
Verified affected surfaces:
-
PSD
PsdImageFile.seek()can switch from grayscale/nativeLstorage to RGB layer decoding while retaining_im. This produces attacker-controlled native out-of-bounds writes and reliable crashes. -
MPO/JPEG A crafted two-frame MPO can make frame 0 allocate
Lstorage, then make frame 1 decodeCMYK/RGBdata into the retainedLstorage. The documentedImageSequence.Iteratorpath reaches this withframe.load(). Verified native memory corruption, crash, over-read behavior, and scoped harmless-marker command execution on Pillow 12.3.0. -
DCX
DcxImageFile.seek()callsPcxImageFile._open(), which changes mode/tile state without a native-storage mode guard. A crafted DCX withLthenRGBPCX frames produces retained-storage mismatch and crash. -
MIC MIC can call
TiffImageFile._open()directly and bypass TIFF's normal guardedseek()behavior. With aNextIFD-based reachable frame transition, this produces retained-storage mismatch and crash.
TIFF appears to be a useful positive control because its seek() path checks both size and mode before reusing storage.
Impact
- Process crash / denial of service
- Native out-of-bounds write
- Native over-read in the MPO path
- Command execution in matching Python/Pillow runtime profiles through the MPO/JPEG path
Server-side deployment impact:
- A local vulnerable web upload service that accepts an unauthenticated MPO upload and automatically processes it with Pillow requires only one HTTP request and no user interaction after upload.
- The fixed harmless command-output marker succeeded 10/10 times.
- The
_im=Nonecontrol was clean 10/10 times.
Reproduction Evidence
Tested version:
Pillow 12.3.0
MPO terminal proof environments:
Python 3.12.3 + Pillow 12.3.0, clean PyPI environment:
marker 10/10, control 0/10
Python 3.13.14 + Pillow 12.3.0, prepared profile:
marker 10/10, control 0/10
Server-side web-upload proof:
control 1..10: MARKER_MISSING
control_summary ok 0 missing 10 /10
vulnerable 1..10: MARKER_OK marker_output <server-user>
vulnerable_summary ok 10 missing 0 /10
The terminal proof uses a fixed harmless marker command only. It does not use a reverse shell, persistence, data exfiltration, or arbitrary attacker-selected commands.
The following private artifacts can be provided to maintainers:
- Minimal crash fixtures for PSD, MPO, DCX, and MIC
- Non-weaponized MPO marker PoC
- Local vulnerable web upload demo
- gdb/GEF geometry receipts
- Control-run logs
- Proposed regression-test shape
Minimal Reproduction Shape
For the MPO path, the vulnerable consumer shape is:
from io import BytesIO
from PIL import Image, ImageSequence
source = BytesIO(open(path, "rb").read())
image = Image.open(source)
iterator = ImageSequence.Iterator(image)
next(iterator).load()
next(iterator).load()
The crafted image shape is:
frame 0: mode L, dimensions W x H
frame 1: same W x H, wider mode such as CMYK
Frame 0 allocates native L storage. Frame 1 changes the logical mode and decoder state but can reuse the old native storage. The frame 1 decoder writes using the wider mode into the narrow storage.
Suggested Fix Direction
Before reusing native ImagingCore storage, Pillow should verify that the retained storage is compatible with the current logical image mode and size.
A central guard in ImageFile.load_prepare() could compare native storage mode/size against self.mode / self.size and allocate fresh storage when they differ. Alternatively, every mode-changing seek() / _open() path should explicitly invalidate _im before decoding.
Caution: TIFF has specialized tile-size behavior and already has a mode/size guard, so a central fix should avoid regressing TIFF tile-buffer handling.
Credit
Rotem Kama
Methodology Note
AI-assisted analysis was used for discovery and verification support. Claims in this report are limited to the local artifacts, controls, and command outputs described above.
What to do
Upgrade Pillow to version 13.0.0 or later.
Affected software
Click a technology to see all vulnerabilities affecting it.
| Platform | Package | Vulnerable versions | Fixed in |
|---|---|---|---|
| Python (PyPI) | pillow | >= 11.0.0, < 13.0.0 | 13.0.0 |
References
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-v9pv-5gc8-w2m6
- https://nvd.nist.gov/vuln/detail/CVE-2026-96639
- https://github.com/python-pillow/Pillow/pull/10105
- https://github.com/python-pillow/Pillow/commit/78d97d994579aef81aafe123773d525f40f2522a
- https://github.com/python-pillow/Pillow
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0
- CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H- Weakness (CWE)
CWE-125, CWE-787- Platform
- Python (PyPI)
- Package
pillow- Disclosed
- 22.10.2026
- Updated
- 23.10.2026 00:03
Sources and licenses · Edited or translated by DockRay; source rights and applicable licenses are retained.
OSV / GitHub Advisory Database - GHSA-v9pv-5gc8-w2m6 - CC BY 4.0
Vulnerability history: pillow
All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.
- Total entries
- 100
- First → latest
- 04.2014 10.2026
- Without a fix
- 0
- Exploited in attacks
- 1
Severity breakdown
- Critical 13
- High 58
- Medium 27
- Low 1
- Unrated 1
Disclosures per year
- 2017: 1
- 2018: 0
- 2019: 1
- 2020: 10
- 2021: 20
- 2022: 8
- 2023: 3
- 2024: 2
- 2025: 1
- 2026: 42
earlier: 12
-
Pillow multi-frame loaders can reuse stale native image storage after mode transitions this entry
Know which vulnerabilities affect your application
With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.