Skip to content

Handle TIFF JPEG sampling mismatches safely - #193

Merged
danoli3 merged 2 commits into
masterfrom
followup/pr191-safe-tiff-ico
Oct 22, 2026
Merged

danoli3 merged 2 commits into
masterfrom
followup/pr191-safe-tiff-ico

Conversation

@danoli3

@danoli3 danoli3 commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

This follow-up preserves the history from PR #191: the first commit is @haobinnan's original change, followed by the safe implementation and regression tests here.

The three TIFF samples shared in #191 all have 2x2 YCbCr subsampling in the TIFF tags but 2x1 factors in the embedded JPEG frame. The loader now handles that supported contiguous YCbCr mismatch through libjpeg's full-resolution RGB path, so raw-plane sizing does not depend on inconsistent factors. Unsupported mismatch types still fail safely. The generated regression test reproduces the same 2x1 JPEG versus 2x2 TIFF mismatch and checks decoded pixels against a matching-metadata reference. It fails with the original strict rejection.

The ICO pixel cap uses division after validating positive dimensions, avoiding signed multiplication overflow. A crafted header-only ICO test checks that dimensions whose product overflows are rejected without allocating image pixels.

Attribution: the original report and proposed compatibility change are by @haobinnan in PR #191. The shared source images were used to confirm the exact sampling-factor discrepancy; they are not included in the repository.

Validation: CMake Debug build with bundled codecs; all 10 CTest tests pass. The updated focused vendor-codec test also passes.

… factors

- PluginICO: reject icons whose pixel count exceeds 4096*1024 (~4M pixels)
  to prevent memory allocation errors caused by abnormally large dimensions.

- LibTIFF4/tif_jpeg.c: comment out the JPEG sampling-factor mismatch check
  in JPEGComputeStrileWidthHeightBytesPerLine(). The strict check caused
  JPEG-compressed TIFF images with mismatched sampling factors to fail to
  load; decoding now proceeds instead of returning early.

Signed-off-by: haobinnan <[email protected]>
@danoli3
danoli3 force-pushed the followup/pr191-safe-tiff-ico branch from 91f6e81 to 3ef27bc Compare October 21, 2026 05:12
@haobinnan

Copy link
Copy Markdown
Contributor

Once the TIFF issue is resolved, I recommend submitting the fix to the upstream libtiff project and getting it merged. This way, future libtiff updates will include the fix, and we won't need to maintain or reapply a separate patch every time we update the library.@danoli3

Decode supported YCbCr sampling mismatches through the full-resolution RGB path, where TIFF raw-plane sizing is not used. Reject unsupported mismatches and add a generated regression fixture that checks decoded pixels against a matching reference.

Use division-based ICO pixel-limit validation to prevent signed multiplication overflow, with a header-only crafted ICO regression test.

Follow-up to haobinnan's report and compatibility change in PR #191.
@danoli3
danoli3 force-pushed the followup/pr191-safe-tiff-ico branch from 3ef27bc to 4c7b7cb Compare October 22, 2026 05:04
@danoli3
danoli3 merged commit b6cac9c into master Oct 22, 2026
66 checks passed
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.

2 participants