Skip to content

[V4] Apply TIFF sample-depth defaults without changing invalid layouts - #3254

Merged
JimBobSquarePants merged 3 commits into
release/4.1.xfrom
fix/tiff-default-bitspersample-v4
Oct 27, 2026
Merged

JimBobSquarePants merged 3 commits into
release/4.1.xfrom
fix/tiff-default-bitspersample-v4

Conversation

@JimBobSquarePants

Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

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

  • Release .NET 8: 747 TIFF-related and shared decoder tests passed.
  • Release .NET 10: the same 747 tests passed.
  • Stored input hashes match the reviewed main branch.
  • No public API, tolerance or reference-image changes.

Backports #3230. Addresses #3242 for V4.

jafin and others added 2 commits October 27, 2026 14:41
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.
@JimBobSquarePants JimBobSquarePants linked an issue Oct 27, 2026 that may be closed by this pull request
4 tasks done
@JimBobSquarePants
JimBobSquarePants marked this pull request as ready for review October 27, 2026 05:01
@JimBobSquarePants
JimBobSquarePants merged commit 2bcb59f into release/4.1.x Oct 27, 2026
10 checks passed
@JimBobSquarePants
JimBobSquarePants deleted the fix/tiff-default-bitspersample-v4 branch October 27, 2026 05:01
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.

TIFF without a BitsPerSample entry fails to decode or reports 0 bits per pixel

2 participants