Repository navigation
Default a missing TIFF BitsPerSample to one bit per sample - #3230
Merged
JimBobSquarePants merged 4 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.
4 tasks done
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
Use one bit per sample when a TIFF directory omits BitsPerSample. SamplesPerPixel also defaults to one. TIFF 6.0 defines these defaults on pages 29 and 39. Decode and Identify now report the correct bit depth for uncompressed and CCITT Group 4 bilevel files.
Keep file defaults separate from new metadata defaults. The shared eight-bit RGB default was initialized before its source field and therefore contained zero sample depths. Initialize that alias after the RGB field, and document the distinction on the metadata types.
A present but unusable BitsPerSample entry keeps its existing handling instead of inheriting a valid RGB default. When BitsPerSample is absent, reject SamplesPerPixel values outside the supported one-to-four range instead of silently changing the declared layout. This structural check remains fatal in every SegmentIntegrityHandling mode.
Testing
All new decoder inputs are stored files. Seven small TIFFs (3,396 bytes total) are derived from the existing basi3p02_fax4 fixture. Their active IFDs are sorted, with independently verified tag values. Pillow confirms exact source pixels for all three valid missing-tag files; Group 4 decoding uses libtiff.
Tests cover uncompressed and Group 4 data, both sample tags absent, unsupported sample counts, present invalid depth tags, and new image/frame metadata defaults. Decoder cases use the public Decode and Identify paths under all integrity modes. The runtime encoder setup and tag-rewriting helper were removed.
Six of the eight focused regressions fail on current main. All eight pass with the corrections. Release .NET 10: 869 TIFF-related and shared decoder tests passed.
No tolerances or reference images changed. The branch includes current main.
Fixes #3242.