Skip to content

fix(tiff): hardening: prevent OOB read, overflow protection - #5336

Open
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-tiff-hardening
Open

fix(tiff): hardening: prevent OOB read, overflow protection#5336
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-tiff-hardening

Conversation

@lgritz

@lgritz lgritz commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

In the raw-strip read path of read_native_scanlines(), a failed TIFFReadRawStrip() returns csize < 0. Bail out of the strip loop for this case before running the decompress, matching the existing tiled path (read_native_tiles already breaks on this condition), and guard the leftover-scanline loop with ok so it doesn't run after the bail.

Add regression seed to the TIFF corpora -- a valid DEFLATE TIFF with StripOffsets[0] pointing past EOF that the nightly ASan fuzz job exercises via full-image reads. The reader now rejects it with a clean error instead of reading out of bounds.

Also size scanline scratch with 64-bit arithmetic, for overflow protection.

Assisted-by: Claude Code / Claude Opus 4.8

@lgritz

lgritz commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

This is the first PR in a new initiative I'm taking to proactively look file format by file format and try to uncover potential bugs before the fuzzers or the bad guys even find them. So expect another series of PRs. I will try to organize them into one per format.

@lgritz

lgritz commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

Near as I can tell, the "hobbled" test failures are unrelated to this PR and are happening (nondeterministically) on several branches/PRs. I think it's some kind of GH configuration thing, am looking at it separately.

In the raw-strip read path of read_native_scanlines(), a failed
TIFFReadRawStrip() returns csize < 0.  Bail out of the strip loop for
this case before running the decompress, matching the existing tiled
path (read_native_tiles already breaks on this condition), and guard
the leftover-scanline loop with ok so it doesn't run after the bail.

Add regression seed to the TIFF corpora -- a valid DEFLATE TIFF with
StripOffsets[0] pointing past EOF that the nightly ASan fuzz job
exercises via full-image reads. The reader now rejects it with a clean
error instead of reading out of bounds.

Also size scanline scratch with 64-bit arithmetic, for overflow
protection.

Assisted-by: Claude Code / Claude Opus 4.8

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz
lgritz force-pushed the lg-tiff-hardening branch from 6f26385 to ab3793d Compare July 27, 2026 00:45
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.

1 participant