fix: reject truncated Exp-Golomb codes#398
Open
alexliyu7352 wants to merge 7 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens Exp-Golomb parsing by rejecting truncated ue(v) codewords, propagates those parse failures through H.264/H.265/H.266 parameter-set update paths, and adds regression tests to ensure malformed parameter sets fail without altering stored decoder configuration arrays.
Changes:
- Update
mpeg4_h264_read_ueto return an error for incomplete/truncatedue(v)codewords and propagate failures to SPS/PPS parsing. - Ensure H.265/H.266 parameter-set copy/update paths treat failed ID parsing as an update error.
- Add regression tests for truncated PPS inputs to verify clean failure without mutating stored arrays/offsets.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| libflv/source/mpeg4-annexbtomp4.c | Makes ue(v) parsing reject truncated codewords and updates AVC SPS/PPS update logic + regression test. |
| libflv/source/hevc-annexbtomp4.c | Propagates ue(v) parse failures through HEVC SPS/PPS parsing and update flow + regression test. |
| libflv/source/vvc-annexbtomp4.c | Propagates ue(v) parse failures through VVC PPS parsing and update flow + regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
alexliyu7352
marked this pull request as draft
July 20, 2026 09:04
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
libflv/source/hevc-annexbtomp4.c:170
sps_temporal_id_nesting_flagis assigned but never used, which can trigger unused-variable warnings (often treated as build failures under -Werror). Remove the variable/assignment to keep the build warning-free.
uint8_t sps_max_sub_layers_minus1;
uint8_t sps_temporal_id_nesting_flag;
uint8_t conformance_window_flag;
uint32_t value;
libflv/source/hevc-annexbtomp4.c:320
hevc_vps_id(...)mutateshevc(profile/tier/level + temporal layer fields). Inh265_vps_copy, calling it inside the search loop overwrites the fields parsed from the new VPS with values from each stored VPS. If no stored VPS matches and the new one is added,hevccan end up reflecting the last probed stored VPS rather than the newly added VPS.
if (0xFF == vpsid)
return -1;
for (i = 0; i < hevc->numOfArrays; i++)
{
if (H265_NAL_VPS == hevc->nalu[i].type && vpsid == hevc_vps_id(hevc->nalu[i].data, hevc->nalu[i].bytes, hevc, hevc->data + hevc->off, sizeof(hevc->data) - hevc->off))
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
alexliyu7352
marked this pull request as ready for review
July 20, 2026 22:22
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.
Summary
Why
The previous parser could reach the end of a truncated code word without a complete suffix, then use a partial value. Malformed SPS/PPS data could therefore be accepted or trigger invalid shift/assertion behavior.
Impact
Malformed H.264, H.265, and H.266 parameter sets now fail cleanly while valid inputs retain the existing behavior.
Validation