Repository navigation
fix: reject malformed HEVC config and zero-size fMP4 boxes instead of crashing - #134
Open
prostomarkeloff wants to merge 1 commit into
Open
prostomarkeloff wants to merge 1 commit into
prostomarkeloff wants to merge 1 commit into
Conversation
… crashing Two parsers of untrusted input panicked or looped on malformed data: - codec/h265parser AVCDecoderConfRecord.Unmarshal read spscount/ppscount without the len(b) < n+1 guard its h264parser twin has, so a ~30-byte truncated hvcC record indexed past the slice (index out of range). Add the guards, mirroring h264parser. - format/fmp4/fmp4io box loops advanced by the child box's own size field (n += size) with no size>=8 check, so a child box declaring size 0 looped forever, appending without bound (the format/mp4/mp4io twins cap this). Add a `size < 8` guard to each loop, erroring out as mp4io does.
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.
Found with find-dup-defs using its converge pass, which flagged these parsers against their siblings (h265parser vs h264parser; fmp4io vs mp4io) as near-duplicates that had dropped a guard.
Two denial-of-service defects when parsing untrusted media:
1.
codec/h265parserAVCDecoderConfRecord.Unmarshalreads the SPS and PPS counts (b[n]) after twon++increments with no bounds check, unlike theh264parsertwin which guards each count read withif len(b) < n+1 { return ErrDecconfInvalid }. A ~30-byte truncated HEVC decoder-config record drivesb[n]past the end →index out of rangepanic. Fix: add the same guards before readingspscountandppscount.2.
format/fmp4/fmp4iobox-reading loops advance by the child box's declared size (n += size) with only an upper-boundlen(b) < n+sizecheck. A child box withsize == 0never advancesn, so the loop appends children forever and allocates without bound. Theformat/mp4/mp4iotwins cap this (len(self.Unknowns) > 100→ error);fmp4iohad no guard. Fix: addif size < 8 { ... return }(a box cannot be smaller than its own 8-byte header) to each of the 14 loops.Regression tests: a truncated hvcC record (h265parser) and a zero-size child box (fmp4io, compared against the mp4io twin) — each panics/hangs before the change and returns an error after.
Disclosure: prepared with the help of an AI tool; I have reviewed the changes and tests and understand each line.