Repository navigation
fix(jpeg): stop the scan reader at a marker, refuse an empty scan - #212
Merged
Merged
Conversation
The nightly fuzzer found a mutated 8x8 JPEG that decoded with scan range [607, 607). BitReader.fill() advanced past the 0xFF of a marker before noticing it, so the stop lasted one byte: the next fill read the marker code and everything after it as entropy data, decoding coefficients from outside [scanStart, scanEnd). The reader now steps back onto the 0xFF, so every later fill stops there and pads (still bounded by MAX_PAD_BYTES). decodeScan also refuses an empty scan, which a permissive DHT can otherwise decode from padding alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes the nightly Fuzz failure (run 36413702903):
decodeJpeg: accepted 701 bytes and returned scan range [607, 607).Cause
BitReader.fill()consumed the0xFFof a marker before recognising it, so the stop lasted one padded byte. The next fill read the marker code and whatever followed as entropy data. The mutated file's scan began withFF 6F, so every coefficient came from bytes outside[scanStart, scanEnd), whilefindScanEndcorrectly reported an empty range. Well-formed files never hit this because the reader finishes before the marker.Fix
0xFF, so every later fill stops there and pads, still bounded byMAX_PAD_BYTES.decodeScanrefuses an empty scan (JpegUnsupportedError), which a permissive DHT can otherwise decode from padding alone.Tests
src/core/jpeg-coeff.test.ts: an empty forged 8x8 scan, and a scan with one real byte, a marker, then 20 decodable bytes. Both fail before the fix and pass after.npm run fuzz -- --iters=200000 --seed=36413702903.🤖 Generated with Claude Code