Repository navigation
fix(libobs): get_ue_golomb UB on a truncated SPS (1 << 32) - #17
Merged
Merged
Conversation
…(RED for #11) obs_parse_avc_header on an SPS that ends right after the level byte makes get_ue_golomb count 32 leading zeros and evaluate 1 << 32. The test compiles obs-avc.c with -fsanitize=undefined -fno-sanitize-recover where the toolchain supports it, so the UB aborts the test. Added to the Tier 2 target lists (Linux, macOS, Windows).
#11) On a truncated or malformed SPS the bitstream reader returns 0 past the end, so get_ue_golomb counted 32 leading zeros and evaluated 1 << 32, undefined behavior (and 1 << 31 overflowed int). Cap the count at 31, the most a valid ue(v) has, and compute with an unsigned shift. Valid input is unaffected; test_avc goes GREEN under UBSan. Closes #11 Local-Gate: v1 tree=522f3ed0e7d811b504351a747d5939f6e3802cde secs=53 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791509701,"gate":"rust/all/fmt","host":"linux-x86_64","key":"9b8ead564a49f74e170d8f91590327aa355cfb99ab8eaa5a30be2e2950a675a2","lane":"lint","parents":["5b01120fb64be07c7f361d7ae3078ecf43940f54"],"secs":14,"stamp":"66346a49a592ac7012d76c16e9f5d1ee","tree":"522f3ed0e7d811b504351a747d5939f6e3802cde","v":1,"via":"run"} Ci-Attestation: {"at":1791509701,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"9b8ead564a49f74e170d8f91590327aa355cfb99ab8eaa5a30be2e2950a675a2","lane":"lint","parents":["5b01120fb64be07c7f361d7ae3078ecf43940f54"],"secs":14,"stamp":"c86a616ff8501783665dfb1d6caa259a","tree":"522f3ed0e7d811b504351a747d5939f6e3802cde","v":1,"via":"run"} Ci-Attestation: {"at":1791509701,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"57d0cdbed6b046cd49e037050c3d98e2cbd30dc535f666b52c360db558094159","lane":"rust-test","parents":["5b01120fb64be07c7f361d7ae3078ecf43940f54"],"secs":4,"stamp":"7acae19b769c260afb6a3df2b8a3be58","tree":"522f3ed0e7d811b504351a747d5939f6e3802cde","v":1,"via":"run"} Ci-Attestation: {"at":1791509701,"gate":"general/linux-x64/tier2","host":"linux-x86_64","key":"6d6c804fa30509892a9fbe1ec2ddfe1dfb406282db6a4633d838512a274d27c8","lane":"tier2-linux","parents":["5b01120fb64be07c7f361d7ae3078ecf43940f54"],"secs":35,"stamp":"ab7e8bdda5e16251f3ff10c658a70b9c","tree":"522f3ed0e7d811b504351a747d5939f6e3802cde","v":1,"via":"run"}
This was referenced Oct 9, 2026
b7216309-jpg
added a commit
to b7216309-jpg/obs-studio
that referenced
this pull request
Oct 10, 2026
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. Every function walks the NAL units as the C loop does: skip zeros and one more byte after each start code, stop when that reaches the end. Outputs are bmalloc'ed like the C serializer and DARRAY buffers, with the long reference count in front of a parsed packet. The SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from the obs-nal port: on NULL data with size 0 these functions give empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
6 tasks done
zackees
pushed a commit
to b7216309-jpg/obs-studio
that referenced
this pull request
Oct 10, 2026
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. Every function walks the NAL units as the C loop does: skip zeros and one more byte after each start code, stop when that reaches the end. Outputs are bmalloc'ed like the C serializer and DARRAY buffers, with the long reference count in front of a parsed packet. The SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from the obs-nal port: on NULL data with size 0 these functions give empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
pushed a commit
to b7216309-jpg/obs-studio
that referenced
this pull request
Oct 10, 2026
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. Every function walks the NAL units as the C loop does: skip zeros and one more byte after each start code, stop when that reaches the end. Outputs are bmalloc'ed like the C serializer and DARRAY buffers, with the long reference count in front of a parsed packet. The SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from the obs-nal port: on NULL data with size 0 these functions give empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
pushed a commit
to b7216309-jpg/obs-studio
that referenced
this pull request
Oct 10, 2026
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. The NAL walk, AVCC conversion, priority scan and header split use the shared helpers in obs-codec::nal; AVC adds its unit rating (IDR is a keyframe, priority header >> 5) and the AVCDecoderConfigurationRecord builder. The SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from the obs-nal port: on NULL data with size 0 these functions give empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
pushed a commit
to b7216309-jpg/obs-studio
that referenced
this pull request
Oct 10, 2026
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. The NAL walk, AVCC conversion, priority scan and header split use the shared helpers in obs-codec::nal; AVC adds its unit rating (IDR is a keyframe, priority header >> 5) and the AVCDecoderConfigurationRecord builder. The SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from the obs-nal port: on NULL data with size 0 these functions give empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
b7216309-jpg
added a commit
to b7216309-jpg/obs-studio
that referenced
this pull request
Oct 10, 2026
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. The port is AVC's classification on the NAL walk and packet helpers already shared by the HEVC port: the unit type is the low 5 bits; an IDR unit makes a keyframe; priority is header >> 5. On top of that, the SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from obs-nal: NULL data with size 0 gives empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
b7216309-jpg
added a commit
to b7216309-jpg/obs-studio
that referenced
this pull request
Oct 10, 2026
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. The port is AVC's classification on the NAL walk and packet helpers already shared by the HEVC port: the unit type is the low 5 bits; an IDR unit makes a keyframe; priority is header >> 5. On top of that, the SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from obs-nal: NULL data with size 0 gives empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
b7216309-jpg
added a commit
to b7216309-jpg/obs-studio
that referenced
this pull request
Oct 10, 2026
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. The port is AVC's classification on the NAL walk and packet helpers already shared by the HEVC port: the unit type is the low 5 bits; an IDR unit makes a keyframe; priority is header >> 5. On top of that, the SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from obs-nal: NULL data with size 0 gives empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
pushed a commit
to b7216309-jpg/obs-studio
that referenced
this pull request
Oct 10, 2026
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. The NAL walk, AVCC conversion, priority scan and header split use the shared helpers in obs-codec::nal; AVC adds its unit rating (IDR is a keyframe, priority header >> 5) and the AVCDecoderConfigurationRecord builder. The SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from the obs-nal port: on NULL data with size 0 these functions give empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 11, 2026
This was referenced Oct 28, 2026
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.
Item 2 of #13. Fixes the undefined behavior in
get_ue_golomb(libobs/obs-avc.c) on a truncated SPS.Change
get_ue_golomb: a valid ue(v) has at most 31 leading zeros, so the leading-zero count is capped at 31 and the value is computed with1u << i. Before, a truncated or malformed SPS made the loop count 32 zeros, because the bitstream reader returns 0 past the end, and then evaluated1 << 32.1 << 31also overflowedint. Valid input gives the same result as before.test/cmocka/test_avc.c(existing C tests untouched). It callsobs_parse_avc_headeron a High-profile (profile_idc 100) SPS that ends right after the level byte, followed by a PPS, and checks the avcC layout. On non-MSVC toolchains,obs-avc.cis compiled into the test with-fsanitize=undefined -fno-sanitize-recover=undefined, so any UB aborts the test. Its definitions take precedence over libobs's.test_avcis added to the Tier 2 target lists inrust/tools/linux-validate/validate.shandrust/tools/tier2-validate/validate.{sh,ps1}. ctest runs it withENABLE_RUST_LIBOBSOFF and ON.Intentional behavior difference, relevant to a future Rust port's Tier 3 parity exclusion: on 32+ leading zeros (garbage input), the decoded value is now well defined (
0xFFafter theuint8_ttruncation). Before, it was undefined, and on x86 it was typically0.RED → GREEN (
./unittest, tier2-linux lane)RED (commit 1, test only):
GREEN (commit 2, fix):
./lintok. Stamped withci-lint local-gate run(lint, rust-test, tier2-linux all passed).Closes #11
Refs #13