Skip to content

libavc: add upper bound check for SEI payload size - #166

Merged
harishdm merged 1 commit into
ittiam-systems:mainfrom
harishdm:sei
Nov 28, 2026
Merged

harishdm merged 1 commit into
ittiam-systems:mainfrom
harishdm:sei

Conversation

@harishdm

Copy link
Copy Markdown
Member

In ih264d_parse_sei_message(), each 0xFF byte read from the bitstream adds 255 bytes to ui4_payload_size while consuming only 1 byte from the buffer. For a large run of 0xFF bytes, passing (ui4_payload_size << 3) to CHECK_BITS_SUFFICIENT causes (u4_ofst + bits_to_read) to overflow UWORD32.

Return ERROR_EOB_GETBITS_T from the 0xFF loop as soon as ui4_payload_size exceeds the number of bytes left in the bitstream. This bounds ui4_payload_size so that (ui4_payload_size << 3) can no longer overflow.

Bug: 514726621
Flag: EXEMPT BUGFIX
Test: atest MctsMediaV2TestCases
Test: atest MctsMediaDecoderTestCases
Test: atest MctsMediaCodecTestCases
Test: atest VtsHalMediaC2V1_0TargetVideoDecTest

Change-Id: I42d25e758ecf4e28f272a1c368f07c051a2b8353 (cherry picked from commit efc40c25f6d1ca30b00b459dec383ec88f20eb8f)

In ih264d_parse_sei_message(), each 0xFF byte read from the bitstream
adds 255 bytes to ui4_payload_size while consuming only 1 byte from the
buffer. For a large run of 0xFF bytes, passing (ui4_payload_size << 3)
to CHECK_BITS_SUFFICIENT causes (u4_ofst + bits_to_read) to overflow
UWORD32.

Return ERROR_EOB_GETBITS_T from the 0xFF loop as soon as
ui4_payload_size exceeds the number of bytes left in the bitstream.
This bounds ui4_payload_size so that (ui4_payload_size << 3) can no
longer overflow.

Bug: 514726621
Flag: EXEMPT BUGFIX
Test: atest MctsMediaV2TestCases
Test: atest MctsMediaDecoderTestCases
Test: atest MctsMediaCodecTestCases
Test: atest VtsHalMediaC2V1_0TargetVideoDecTest

Change-Id: I42d25e758ecf4e28f272a1c368f07c051a2b8353
(cherry picked from commit efc40c25f6d1ca30b00b459dec383ec88f20eb8f)
@harishdm
harishdm merged commit 91041d0 into ittiam-systems:main Nov 28, 2026
10 checks passed
@harishdm
harishdm deleted the sei branch November 28, 2026 17:20
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