Repository navigation
feat!: header checks for TIFF compression, layout, tiles and colour, PNG kind, and metadata size - #3
Merged
Merged
Conversation
…PNG kind, and metadata size Six checks from the November 2026 advisory backfill, landed together so that the version moves once. Each is a field on Policy with a reason in the house style, a case in the hostile corpus, and a reading of real Pillow output to agree with. TIFF. The IFD walk, which read only the dimensions, now reads the compression scheme, photometric interpretation, samples per pixel, bits per sample, tile size and YCbCr subsampling of every frame, and checks every entry's data against the file before anything else (the shape of CVE-2023-6277). tiff_compressions names the schemes that pass, by default the six a scanner writes; PixarLog and the other rare codecs, where most of libtiff's flaws have been (CVE-2026-12912), are refused, and an unknown code is refused outright. Every frame must share the first frame's scheme and pixel layout, since the decoder sizes its buffers from the first (CVE-2026-96639); Pillow's own mixed-mode output is refused. tiff_photometrics and tiff_subsamplings name the colour models and chroma subsamplings that pass (CVE-2026-4775). A tile is reported, held to max_pixels on its own because the decoder allocates it whole, and allow_tiled_tiff refuses tiles under the strict preset (CVE-2026-112395, CVE-2026-112404). PNG. The whole IHDR is decoded and impossible combinations refused. allow_interlaced_png is off by default, as no scanner writes Adam7 and the interlaced 16-bit path was the way into two libpng overflows (CVE-2025-65018, CVE-2026-22695); png_colour_types and max_png_bit_depth are knobs, with the strict preset at 8 bits. The chunk walk now goes to IEND, skipping image data, since a decoder reads the chunks after it too. Metadata. max_metadata_bytes (4 MiB, 1 MiB strict) bounds the largest PNG chunk, TIFF tag's data or JPEG colour profile (CVE-2026-96643). BREAKING CHANGE: a TIFF compressed with a scheme outside none, CCITT, LZW, JPEG, Deflate and PackBits, or with frames that differ in compression or pixel layout, or declaring CIELab, a mask, raw sensor data or LogLuv, or a YCbCr file subsampled by four; an interlaced PNG or one whose IHDR pairs a colour type with a depth it cannot have; and an image with a metadata block over 4 MiB, all passed before and are refused now. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Six header checks from the November 2026 advisory backfill, landed together so that the version moves once (this is the second
feat!; it will release as 2.0.0). Each is a field onPolicywith a reason in the house style, a case in the hostile corpus built at test time, and a reading of real Pillow output to agree with.TIFF
The IFD walk read only the dimensions. It now reads, for every frame, the compression scheme, photometric interpretation, samples per pixel, bits per sample, tile size and YCbCr subsampling, and checks every directory entry's data (count × type size) against the file before anything else, which is the shape of the allocation flaw in libtiff's open path (CVE-2023-6277).
tiff_compressions, default none, CCITT, LZW, JPEG, Deflate, PackBits. PixarLog (CVE-2026-12912) and the other rare codecs, where most of libtiff's security history lives, are refused; a code the library does not know is refused outright.tiff_photometricsandtiff_subsamplings, default the five colour models and four subsamplings a scanner writes; CIELab, masks, raw sensor data, LogLuv and the factor-of-four chroma paths (CVE-2026-4775) are refused.allow_tiled_tiff, on by default (digitisation and mapping software write tiles) and off underSTRICT. A tile is held tomax_pixelson its own, since the decoder allocates it whole (CVE-2026-112395, CVE-2026-112404).PNG
The whole IHDR is decoded and impossible combinations refused.
allow_interlaced_pngis off by default: no scanner writes Adam7, and the interlaced 16-bit path was the way into two libpng overflows (CVE-2025-65018, CVE-2026-22695).png_colour_types(default all five) andmax_png_bit_depth(16, or 8 underSTRICT) are knobs. The chunk walk now goes to IEND, skipping image data, since a decoder reads the chunks after it too; a 19.8 MB PNG costs under a millisecond with 64 KiB image-data chunks and 5 ms with libpng's 8 KiB ones.Metadata
max_metadata_bytes(4 MiB, 1 MiB strict) bounds the largest PNG chunk, TIFF tag's out-of-line data, or JPEG colour profile summed across its APP2 segments (CVE-2026-96643, CVE-2024-28219). Pillow refuses a PNG text chunk over 1 MiB on its own; the default leaves room for a large profile or XMP.Why breaking
A TIFF compressed with a scheme outside the six, or with frames that differ in compression or pixel layout, or declaring CIELab, a mask, raw sensor data or LogLuv, or a YCbCr file subsampled by four; an interlaced PNG or one whose IHDR pairs a colour type with a depth it cannot have; and an image with a metadata block over 4 MiB: all passed before and are refused now. Under
AGENTS.mdthat is a!.Notes for review
Factsgainscompression,metadata,colour,depth,interlaced,tileandsubsampling;colouranddepthare shared by PNG and TIFF so the facts read alike. All appear in--jsonoutput.tiff_compressionswidened.Checks
ruff check,ruff format --check,mypy,pytest --cov(294 tests, 98%) anduv lock --checkpass locally.🤖 Generated with Claude Code