Repository navigation
fix: prevent panics in EXIF/TIFF tag parsing on truncated input - #9
Merged
vbasky merged 1 commit intoSep 8, 2026
Merged
Conversation
parse_tags runs on every analyzed file, so these crash the top-level Metadata::from_bytes / from_path on malformed or truncated media: - parse_exif reads head[0..2] to check the TIFF byte-order mark, but peek_raw_at returns a *partial* window that can be shorter than the 12 bytes requested. A 1-byte input panics with 'range end index 2 out of range for slice of length 1'. - read_tiff_u16 / read_tiff_u32 index data[off..off+N] with no bounds check, unlike the sibling read_tiff_f32 / read_tiff_f64 which already guard 'off + N > data.len()'. A truncated TIFF/EXIF IFD panics with 'index out of bounds: the len is N but the index is N'. Guard head.len() < 12 before indexing, and add the same bounds check to the integer readers (returning 0 when out of range, matching the float readers). Adds regression tests. Found by feeding mutated/truncated format-signature inputs to Metadata::from_bytes and asserting no parser panics.
Owner
|
Thanks @chiliec for this fix — great find and write-up. I reviewed and verified it end-to-end: I reproduced all three panics on |
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.
What
parse_tagsruns on every analyzed file (Metadata::from_bytes/from_pathcall it after detection), so a panic there crashes the top-level API on malformed or truncated media. Two out-of-bounds panics, both reachable from any input:parse_exif— short partial windowpeek_raw_atreturns a partial window, soheadcan be shorter than the 12 bytes requested. A 1-byte input panics:The existing
buf.len() < 12guard is checked after thishead[0..2]read.read_tiff_u16/read_tiff_u32— unchecked indexingThese index
data[off..off+N]with no bounds check, unlike the siblingread_tiff_f32/read_tiff_f64which already guardoff + N > data.len(). A truncated TIFF/EXIF IFD panics:Fix
head.len() < 12inparse_exifbefore indexinghead[0..2].off + 2 > data.len()/off + 4 > data.len()guards toread_tiff_u16/read_tiff_u32, returning0when out of range — mirroring the existing float readers.Testing
Added
tiff_int_readers_reject_out_of_rangeandparse_exif_handles_short_partial_window. Verified RED→GREEN — reverting each guard reproduces the exact panic above; with the fix the parsers return normally. Existing tag-crate tests still pass (77),cargo fmtclean, no new clippy warnings.How it was found
By feeding format-signature seeds (TIFF/EXIF, RIFF, MP4, FLAC, EBML, …) mutated with truncation, byte-flips and length extension into
Metadata::from_bytesundercatch_unwind(~480k inputs). These were the only panics; both trace back to the tag parser.