Repository navigation
[V4] Apply TIFF sample-depth defaults without changing invalid layouts - #3254
Merged
JimBobSquarePants merged 3 commits intoOct 27, 2026
Merged
Conversation
TIFF 6.0 defines a default of one bit for each sample when the BitsPerSample entry is absent, and bilevel fax and scanner files often omit it. The decoder assumed 8-bit RGB instead, so such files failed to decode or reported the wrong bit depth. The default now uses one bit for each of the SamplesPerPixel samples.
Keep absent file tags separate from newly constructed RGB metadata. Initialize the shared eight-bit RGB alias after the value it references. Preserve zero sample depths for unusable present entries instead of inheriting RGB defaults. Reject unsupported SamplesPerPixel counts when resolving an absent BitsPerSample tag, so the four-channel representation cannot silently change the file layout. Document the file defaults from TIFF 6.0 pages 29 and 39 at the parsing boundary. Replace the PR's runtime TIFF encoding and tag rewriting with seven stored files (3396 bytes), derived from the existing basi3p02_fax4 fixture. Verify sorted IFDs and exact tag values independently; Pillow/libtiff confirms the valid missing-tag variants retain the original pixels. Test Decode, Identify, frame metadata, and all integrity modes through existing APIs. Remove the tag-rewriting helper. Six of eight focused regressions fail on current main. All eight now pass. Release .NET 10: 869 TIFF-related and shared decoder tests passed. No tolerances or reference images changed.
4 tasks done
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.
Prerequisites
Description
Backport #3230 and its review corrections to current release/4.1.x. Keep this draft until the main fix is merged.
Decode and Identify use one bit per sample when BitsPerSample is absent, with SamplesPerPixel defaulting to one. Keep these TIFF file defaults separate from the eight-bit RGB defaults of new metadata objects. Correct the shared default's static initialization order and document both behaviors.
When BitsPerSample is absent, reject unsupported sample counts instead of reducing them to four. This structural check remains fatal in every integrity mode. Present invalid sample depths do not inherit the missing-tag default or the new-metadata RGB default.
The tests use the same seven stored inputs as the main fix (3,396 bytes total). They cover missing tags, uncompressed and Group 4 pixels, invalid sample counts, invalid depth entries and new metadata defaults. Active IFDs are sorted and independently checked. Pillow verifies unchanged pixels for the valid variants, with libtiff handling Group 4 decoding. No decoder input is generated or rewritten during tests.
Verification
Backports #3230. Addresses #3242 for V4.