Skip to content

fix: bound num_ref_frames_in_pic_order_cnt_cycle in AVC SPS parsing - #550

Open
ChrisJr404 wants to merge 1 commit into
Eyevinn:masterfrom
ChrisJr404:fix-sps-num-ref-frames-overflow
Open

fix: bound num_ref_frames_in_pic_order_cnt_cycle in AVC SPS parsing#550
ChrisJr404 wants to merge 1 commit into
Eyevinn:masterfrom
ChrisJr404:fix-sps-num-ref-frames-overflow

Conversation

@ChrisJr404

Copy link
Copy Markdown

While fuzzing the un-fuzzed codec bitstream parsers, I found that avc.ParseSPSNALUnit uses num_ref_frames_in_pic_order_cnt_cycle straight from the bitstream to size a slice, so a tiny malformed SPS NAL unit can force a multi-gigabyte allocation.

Failure mode: when pic_order_cnt_type == 1, the parser reads num_ref_frames_in_pic_order_cnt_cycle as an Exp-Golomb value and immediately does make([]uint, numRefFramesInPicOrderCntCycle). The field is unbounded, so a 22-byte input encoding a ~1e9 value makes ParseSPSNALUnit allocate ~9 GB (measured) before the read loop hits EOF — an out-of-memory / denial-of-service on attacker-controlled input.

Fix: the spec (ISO/IEC 14496-10 Section 7.4.2.1.1) constrains num_ref_frames_in_pic_order_cnt_cycle to the range 0-255. Reject values above that via reader.SetError and return before allocating, matching the existing bound-check style used in hevc/sps.go. Valid streams decode byte-identically.

Test: added TestSPSParserNumRefFramesInPicOrderCntCycle, which feeds the fuzzer-found NAL unit and asserts an error is returned. Before the fix the test hangs the process in a multi-GB allocation (20s timeout); after the fix it returns an error in microseconds. Existing tests still pass.

An out-of-range num_ref_frames_in_pic_order_cnt_cycle was used directly to
size a slice, so a tiny malformed SPS NAL unit could make ParseSPSNALUnit
allocate multiple gigabytes. Reject values outside the spec range 0-255
(ISO/IEC 14496-10 7.4.2.1.1) before allocating.
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