Skip to content

feat!: refuse a file whose tags claim more data than it holds - #29

Merged
stephen-masters merged 1 commit into
mainfrom
feat/overlapping-tag-data
Nov 16, 2026
Merged

stephen-masters merged 1 commit into
mainfrom
feat/overlapping-tag-data

Conversation

@stephen-masters

Copy link
Copy Markdown
Contributor

Closes #26 (CVE-2026-128066, Pillow: memory denial of service in TIFF and EXIF directory parsing through overlapping tag data).

This is breaking and cuts 6.0.0: a file that passed 5.1.0 can be refused by default.

The triage

We file it as B. The trigger is a tag directory, which is a header: each entry gives the size of its value and where it lies, and the loader reads every value into memory with nothing to stop them all being the same bytes. On 5.1.0 every route passed DEFAULT and STRICT. The advisory's own TIFF was refused only by accident, because its tags point inside the eight-byte header; moved eight bytes on, it passed. Refusing private tags did not help, since the standard numbers serve as well.

Each route was tried on Pillow 13.0.0, whose bounded loader warns where it used to read:

Carrier Reaches the loader on Refused now
A TIFF frame's directory Image.open yes
A TIFF's Exif and GPS directories get_ifd yes
A JPEG's EXIF block, before or after the frame header, in one segment or several Image.open yes
A JPEG's multi-picture index Image.open yes
A PNG's eXIf chunk, before or after the image data getexif yes
A PNG's "Raw profile type exif" text chunk getexif no: it may be compressed, and we do not inflate
A camera maker's directory in a maker note not tried no

The change

  • The rule is the one Pillow's fix uses. The values of an honest directory do not overlap, so they cannot add up to more than the bytes they are read from. The readers add them up, against the file for a TIFF and against the block for EXIF and a multi-picture index.
  • Policy.allow_overlapping_tag_data, False under DEFAULT and STRICT; --overlapping-tag-data allows. Facts and Header carry overlaps, a sentence for each directory.
  • A block whose directories hold more entries between them than it has bytes for is refused the same way. That bounds the walk by the size of the block: 500 frames pointing into one 25,000-entry directory read in under 30 ms.
  • A value outside its block is not counted. A decoder reads nothing for it, and cameras write EXIF that sloppy.
  • A JPEG's segments are walked to the image data, not to the frame header. Pillow reads an EXIF block, a colour profile or a multi-picture index from anywhere before the scan, so the reader must too. Up to the frame header a segment it cannot follow is an error, as before; after it the walk stops there, as the decoder does.

What else is refused that was not

  • A JPEG whose colour profile sits after its frame header is now held to max_metadata_bytes, and one whose multi-picture index sits there has its pictures counted and checked.
  • A JPEG with more than 4,096 segments before its image data.

Will it refuse an honest file?

We ran the 5.1.0 reader and this one over about 3.2 million real images (7,501 JPEG, 126,337 TIFF, 3,064,088 PNG). This one reports an overlap in none, and the two agree on every file. A TIFF in which two tags share one value, as some writers store a single resolution, passes, and there is a test for it.

What was not done

  • The memory cost itself was not reproduced on a Pillow before 13.0.0.
  • The two carriers marked "no" above. The README's policy table and the record say so.

Checks

ruff check, ruff format --check, mypy, pytest --cov (499 passed, 99%), uv lock --check, zensical build --clean --strict, advisory_record.py validate, and fuzz_headers.py with the new carriers among its seeds and no findings. The tests check each carrier, and honest files, against Pillow's bounded loader.

🤖 Generated with Claude Code

A decoder reads the value of every tag into memory as it loads a tag
directory, and nothing in the format stops each of thousands of tags
from pointing at the same bytes: a 144 KB TIFF cost Pillow 1.6 GB
inside Image.open, and a 66 KB JPEG 340 MB (CVE-2026-128066). The
values of an honest directory do not overlap, so they cannot add up to
more than the bytes they are read from. The readers now add them up,
and a directory that claims more is refused by default:

- a TIFF: each frame's directory, and the Exif, GPS and
  interoperability directories its tags point to, against the file;
- a JPEG: the main, thumbnail, Exif, GPS and interoperability
  directories of its EXIF block, across every segment that carries it
  and in every picture of a multi-picture file, and its multi-picture
  index, against the block;
- a PNG: the same directories of an eXIf chunk.

A block whose directories hold more entries between them than it has
bytes for is refused the same way, which bounds the walk by the size
of the block. A value that lies outside its block is not counted,
since a decoder reads nothing for it and cameras do write EXIF that
sloppy. Run over 3.2 million real images, the reader reported an
overlap in none.

A JPEG's segments are now walked to the start of the image data, not
to the frame header, because that is how far a decoder reads them: an
EXIF block, a colour profile or a multi-picture index after the frame
header is read by Pillow and is now read here. Up to the frame header
a segment the reader cannot follow is an error, as before; after it
the walk stops there, as the decoder does.

Policy gains allow_overlapping_tag_data, False under DEFAULT and
STRICT; Facts and Header carry `overlaps`; the command line has
--overlapping-tag-data. Not seen, and said so in the README and the
record: EXIF that a PNG holds in a text chunk, which may be compressed,
and a camera maker's own directory inside a maker note.

Closes #26

BREAKING CHANGE: a TIFF, JPEG or PNG with a tag directory whose values
add up to more than the file (or the EXIF block) holds is now refused
by default; allow_overlapping_tag_data=True, or --overlapping-tag-data,
passes one. A JPEG's colour profile and multi-picture index are now
found after its frame header as well as before it, so max_metadata_bytes
and the checks on each picture apply to them there too, and a JPEG with
more than 4,096 segments before its image data is refused.

Co-authored-by: Yvette Mankerian <yvettekm@gmail.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@stephen-masters
stephen-masters merged commit 097aa74 into main Nov 16, 2026
11 checks passed
@stephen-masters
stephen-masters deleted the feat/overlapping-tag-data branch November 18, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CVE-2026-128066: Pillow: Memory DoS in TIFF and EXIF IFD parsing via overlapping tag data

1 participant