Skip to content

ebp: guard flag-driven reads against truncated input - #184

Open
ChrisJr404 wants to merge 1 commit into
Comcast:masterfrom
ChrisJr404:fix/ebp-panic-truncated
Open

ebp: guard flag-driven reads against truncated input#184
ChrisJr404 wants to merge 1 commit into
Comcast:masterfrom
ChrisJr404:fix/ebp-panic-truncated

Conversation

@ChrisJr404

Copy link
Copy Markdown

ReadEncoderBoundaryPoint panics with an index/slice-out-of-range on a truncated EBP whose flag byte advertises fields that aren't actually present, so a malformed stream can crash any caller that parses EBP data.

Failure mode: both readCableLabsEbp and readComcastEbp read the extension, SAP, grouping, time (and partition, for CableLabs) fields based purely on the DataFlags bits, advancing an index into the buffer without checking any bytes remain. A short buffer runs the index off the end. For example ReadEncoderBoundaryPoint([]byte{0xDF, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08}) sets the time flag but omits the 8 time bytes and panics with slice bounds out of range. The CableLabs grouping-extension loop has the same problem and, because the index was a uint8, could also wrap.

Fix: bound-check each flag-driven read and return the existing ErrInvalidEBPLength instead of panicking, and index the buffer with an int so the length math can't wrap. Valid, fully-formed EBPs take the identical path and decode unchanged; existing tests still pass.

Test: adds TestReadEncoderBoundaryPointTruncated covering the truncated CableLabs and Comcast cases. It panics on master and passes with this change. These inputs were found by fuzzing ReadEncoderBoundaryPoint.

ReadEncoderBoundaryPoint panics with an index/slice out of range when
given a truncated EBP whose flag byte advertises fields that are not
actually present. The CableLabs and Comcast readers consume the
extension, SAP, grouping, time and partition fields based on the flag
bits without verifying the buffer still has enough bytes, so a short
buffer runs the read index off the end.

Bound-check each flag-driven read and return ErrInvalidEBPLength instead
of panicking, and index the buffer with an int so the length math cannot
wrap. Found by fuzzing ReadEncoderBoundaryPoint.
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