Repository navigation
feat: a policy on a greyscale or palette TIFF's spare samples - #28
Merged
Merged
Conversation
One field on Policy, allow-by-default so that no file that passed before is refused: - allow_spare_tiff_samples: whether a greyscale or palette TIFF may give each pixel more samples than the one the image uses, where the rest are not a single alpha sample (SamplesPerPixel 2 with ExtraSamples 0, "unspecified data"). Pillow opens such a file as a one-band image while its tag still says two, and a bare save hands that tag to libtiff's encoder, which read two samples for every one in the row it was given: process memory copied into the output, or with a Predictor a write past the row (CVE-2026-128067). A program that saves files from outside back as TIFF refuses them. The reader now reads ExtraSamples. An alpha channel is not spare, and neither is an extra sample on RGB or CMYK, where the decoder's own count is what the encoder is given; a bare save of each layout on Pillow 13.0.0, whose encoder now refuses the mismatch, trips for the greyscale and palette layouts alone. If the tag appears twice, a reading that is not alpha stands. Facts and Header carry `spare_samples`; the command line has --no-spare-tiff-samples; the README documents the field. The corpus gains a complete carrier, which also seeds the fuzzer. The advisory is recorded as B: of the three routes by which a file is the input, this is the one a header shows. The EXIF of a JPEG and the stale size of a rotated TIFF reach the encoder only when the program passes them back, and the record says why neither can be refused. Closes #27 Co-authored-by: Yvette Mankerian <yvettekm@gmail.com> Co-Authored-By: Claude Fable 5.2 <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.
Closes #27 (CVE-2026-128067, Pillow: heap buffer overflow saving a TIFF through libtiff when tags override the image's size).
The triage
The issue was labelled
likely-not-reachedbecause the headline says "saving". Read against the guide's question of what rides from an opened file into a save, the file is the input by three routes, and a header shows one of them. We file it as B.SamplesPerPixel2 andExtraSamples0Image.open(f).save(out, "TIFF")exif=im.getexif()to a compressed TIFF saveOrientationThe change
Policy.allow_spare_tiff_samples,Trueby default underDEFAULTandSTRICT, so nothing that passed before is refused.--no-spare-tiff-sampleson the command line.spare_samplesonHeaderandFacts: the samples each pixel of a greyscale or palette TIFF carries beyond the one the image uses, unless that is a single alpha sample.ExtraSamples. If the tag appears twice, a reading that is not alpha stands.corpus.spare_sample_tiffbuilds a complete carrier that decodes; it also seeds the fuzzer.Why greyscale as well as palette
The advisory names the palette layout. We tried a bare save of each layout on Pillow 13.0.0, whose encoder now refuses a scanline longer than its row ("encoder error -8") where it used to read past it:
PLPALARGBRGBACMYKSo the field covers the first two and nothing else. An alpha channel, and a spare sample on RGB or CMYK, pass whatever the setting.
What was not done
feat!, as it was forallow_inconsistent_tiff_tags, and is a separate decision.Checks
ruff check,ruff format --check,mypy,pytest --cov(455 passed, 99%),uv lock --check,zensical build --clean --strict,advisory_record.py validate, and thirty seconds offuzz_headers.pywith no findings.🤖 Generated with Claude Code