CVE-2026-59204: Pillow JPEG2000 tiled decode retains a growing scratch buffer and can be used for denial of service
High
- OSV id
- GHSA-vjc4-5qp5-m44j
- Also known as
- BIT-pillow-2026-59204, CVE-2026-59204, PYSEC-2026-3496
- Published
- Last modified
Affected packages
| Package | Affected versions | Fixed in |
|---|---|---|
| pillow PyPI |
>= 8.2.0, < 12.3.0 | 12.3.0 |
Versions we track that it affects: pillow 10.4.0
How to fix it
Upgrade pillow to 12.3.0 or later.
# in requirements.txt: change the line to pillow==12.3.0
pip install -r requirements.txt
- If it is an indirect dependency, upgrade the package that depends on it, or add a minimum version constraint for it (e.g. in constraints.txt, or as a dependency in pyproject.toml).
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
Not sure whether your project uses an affected version? Check your lockfile below for free.
Details
Summary
src/libImaging/Jpeg2KDecode.c:853 accumulates total_component_width across every tile in a JPEG2000 image instead of recomputing it per tile. That accumulated value is then used in the tile_bytes calculation at src/libImaging/Jpeg2KDecode.c:868, which can make the decoder grow state->buffer via realloc at src/libImaging/Jpeg2KDecode.c:876 up to roughly one full image's decompressed size even when each tile is small. A crafted tiled JPEG2000 file can therefore force substantially higher transient memory usage and trigger out-of-memory failures during decoding. Based on current evidence, the supported impact is denial of service, not memory corruption.
Details
- Location:
src/libImaging/Jpeg2KDecode.c:853 - Root cause:
total_component_widthis initialized only once before the tile loop and keeps growing across tiles. It is then used to derivetile_bytes, so later tiles are treated as if they had the combined component width of all earlier tiles. - Dangerous operation:
tile_bytesis promoted intotile_info.data_size, thenstate->bufferis grown withreallocatsrc/libImaging/Jpeg2KDecode.c:876. - Reachability: any attacker-controlled JPEG2000 image with many tiles reaches this path during normal
Image.open(...).load()decoding.
PoC
The attached helper script and testcase were used: exercisej2ktile_realloc.zip
Generate the testcase:
pythonexercise_j2k_tile_realloc.py make poc_3664_rgba_tile1832.jp2 \
--size 3664 --tile 1832
Expected geometry from the helper:
- image size:
3664 x 3664 - mode:
RGBA - tile size:
1832 x 1832(2x2tiles) image_bytes=53699584- uncapped RSS observed:
- vulnerable build:
maxrss_kb=180264 - fixed comparison build:
maxrss_kb=138404
- vulnerable build:
Load it with the current vulnerable build:
python exercise_j2k_tile_realloc.py load poc_3664_rgba_tile1832.jp2
Load it again under a 160 MB address-space cap:
python exercise_j2k_tile_realloc.py load poc_3664_rgba_tile1832.jp2 --limit-mb 160
Impact
Conservative impact: denial of service through memory exhaustion during JPEG2000 decoding.
References
- GHSA-vjc4-5qp5-m44j on OSV.dev
- Web: https://github.com/python-pillow/Pillow/security/advisories/GHSA-vjc4-5qp5-m44j
- Advisory: https://nvd.nist.gov/vuln/detail/CVE-2026-59204
- Web: https://github.com/python-pillow/Pillow/pull/9704
- Web: https://github.com/python-pillow/Pillow/commit/13ada41172142f2fd9f0906f615a00ea623a11ca
- Package: https://github.com/python-pillow/Pillow
- Web: https://github.com/python-pillow/Pillow/releases/tag/12.3.0
Am I affected?
Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.
About this data
Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.