Repository navigation
rust: Port obs-av1.c to obs-codec - #105
Conversation
|
Heads-up: #103 (now on master) fixed out-of-bounds reads in |
|
Rebased onto #89's head (rebased on master), no longer stacked on #90/#98: AV1 only needed the
|
C ABI shims for the four exports of libobs/obs-av1.c (obs_av1_keyframe, obs_extract_av1_headers, metadata_obu and metadata_obu_itu_t35), the oracle, rust-exports.txt entries, and Tier 1 and Tier 3 tests against a todo!() core: Tier 1 fails 6/7 and the parity binary aborts. The oracle compiles obs-av1.c with the OBU bounds fix merged from Co-Authored-By: Claude Opus 5.5 <[email protected]>
obs_av1_keyframe, obs_extract_av1_headers, metadata_obu and metadata_obu_itu_t35 move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-av1.c. The OBU walk follows obs-av1.c with the bounds fix from obs-rust#103: - leb128 reads at most 8 bytes into 64 bits; - a missing extension byte ends the OBU; - without a size field the OBU is what follows the header; - the size is cut to what is left, cast as size_t first, as in C. Every OBU is at least its header byte, so the walk always advances and never leaves the buffer. Keyframes come from the first frame or frame header OBU with a payload. metadata_obu builds the header, leb128 size, type, payload and 0x80 trailing bits. No intentional differences. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Feeds arbitrary bytes to the Rust obs-av1 shims and the C oracle (obs-av1.c with the obs-rust#103 bounds fix) and asserts identical results, per the bitstream-parser fuzz rule in docs/rust-port/testing-policy.md. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=9ce794709fd0a6ffd4dbdbb73593a7ea5dd67be4 secs=56 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791656801,"gate":"rust/all/fmt","host":"linux-x86_64","key":"a462edd75576cc3f895aa589808b34f03df55969110a0b83c50da8acba70e0bd","lane":"lint","parents":["fe63e450129c1eeb4b1e1dc1272b678b7305f7d6"],"secs":13,"stamp":"3b9d19058a18740a8119265176b3d64b","tree":"9ce794709fd0a6ffd4dbdbb73593a7ea5dd67be4","v":1,"via":"run"} Ci-Attestation: {"at":1791656801,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"a462edd75576cc3f895aa589808b34f03df55969110a0b83c50da8acba70e0bd","lane":"lint","parents":["fe63e450129c1eeb4b1e1dc1272b678b7305f7d6"],"secs":13,"stamp":"2e06ead6cace504173cfde20d9d37f9c","tree":"9ce794709fd0a6ffd4dbdbb73593a7ea5dd67be4","v":1,"via":"run"} Ci-Attestation: {"at":1791656801,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"d9f9eb5090c7a44b3f2f23547f7d5ca46a72d7107ef48180b3cd47a692710a8f","lane":"rust-test","parents":["fe63e450129c1eeb4b1e1dc1272b678b7305f7d6"],"secs":19,"stamp":"bdf6d4d57719dca99c2e4fdc58f985c0","tree":"9ce794709fd0a6ffd4dbdbb73593a7ea5dd67be4","v":1,"via":"run"} Ci-Attestation: {"at":1791656801,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"8168c5812db09dd001ecdd524685622f754df9c62269d3d1f0d76dccc610456d","lane":"tier2-linux","parents":["fe63e450129c1eeb4b1e1dc1272b678b7305f7d6"],"secs":24,"stamp":"f4a4bb74e724e8dc8cb2544f8b9651d7","tree":"9ce794709fd0a6ffd4dbdbb73593a7ea5dd67be4","v":1,"via":"run"}
|
Rebased onto master after #98 and #88 merged. The cut-down |
…43) Phase 3 ports of libobs/util into the obs-util crate, each with a safe core, a C ABI shim, Tier 1 tests, a layout test where a struct crosses the ABI, and a proptest parity suite against the original C built as an oracle. ENABLE_RUST_LIBOBS=ON drops the matching C sources from libobs. - utf8: hidden and non-Windows only (Windows keeps the C utf8.c). - lexer.c: follows master's C, including the #48 strref ordering. - text-lookup: no longer crashes on an opening quote at end of line; the shim returns false for a NULL lookup. - dstr: follows master's #46/#47 fixes; strlist_split takes a NUL separator. Wide-char and printf helpers stay in dstr-libc.c. - bmem: Windows _aligned_* branch and the allocation counter. The oracle vendors uthash 2.3.0 (BSD-1-Clause) for text-lookup.c, since the Rust test runners have no uthash package. Refs #43 Rebased onto master after #61 (base), #66 (file-serializer) and #85 (real utf8.c in the oracle): the oracle's utf8.c/platform_conv_host.c now use oracle_* utf8 names so they no longer clash with the Rust shims; the dstr-conversion oracle test moved to obs-util and calls oracle_dstr_*; duplicate bcrash/os_fopen/bmemdup/os_*_ptr stand-ins were dropped in favour of master's base-variadic.c, file_serializer_host.c and platform_conv_host.c; utf8 shims are listed in rust-hidden.txt; the vendored uthash is excluded from clang-format. Rebased again onto master after #82/#83/#87/#97/#89/#98/#88/#105: oracle build.rs keeps video_fourcc.c/task.c and drops the direct util/utf8.c (oracle/utf8.c already compiles it under oracle_* names, which platform_conv_host.c and #82's file_serializer_host.c use). Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=58f2156a689831720a1e6ad9004041e400917579 secs=135 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791658556,"gate":"rust/all/fmt","host":"linux-x86_64","key":"e533312cff231c50944045005e90c2b48ce1920b317c9037a705bfda5b49ef4c","lane":"lint","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":17,"stamp":"a33efc3cd6c98f3fbd2fa57e9a61a281","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"} Ci-Attestation: {"at":1791658556,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"e533312cff231c50944045005e90c2b48ce1920b317c9037a705bfda5b49ef4c","lane":"lint","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":17,"stamp":"fb2d0a58bcefb05085a4b512fc916740","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"} Ci-Attestation: {"at":1791658556,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"1a00cb7a8eb7b67b33a108e748711133d604e544b254813435cc1ca5ea24cd26","lane":"rust-test","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":22,"stamp":"d80b75173a27c995da2676193fa36904","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"} Ci-Attestation: {"at":1791658556,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a950373231b455174e5c031fe578e1e48c61e04f0387195a7ddc0e265e371e15","lane":"tier2-linux","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":96,"stamp":"f1c2d81609277e26492a5a3f3553cd9c","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"}
Description
Last step of the parser plan in #45: ports
libobs/obs-av1.ctoobs-codec::av1, all four exports:obs_av1_keyframe,obs_extract_av1_headers,metadata_obuandmetadata_obu_itu_t35. WithENABLE_RUST_LIBOBS=ONlibobs builds withoutobs-av1.c.C fixed first. Reading
obs-av1.cturned up out-of-bounds reads on malformed OBUs: a size field larger than the packet, aleb128shift that overflowsint, an off-by-one without a size field, and an underflow on a lone header. These are fixed in C in #103, withtest/cmocka/test_av1.c. This branch merges #103, and the port matches the fixed C exactly, so there are no intentional differences. Because the fixed C stays in bounds on any input, the parity test feeds both sides arbitrary bytes.The port:
leb128reads at most 8 bytes into 64 bits. A missing extension byte ends the OBU. Without a size field, the OBU is what follows the header (AV1 5.3.1). The size is cast assize_t, like C, then cut to what is left. Every OBU is at least its header byte, so the walk always advances and never leaves the buffer.obs_av1_keyframe: decided by the first frame or frame header OBU with a payload.show_existing_frameis never a key frame; otherwiseframe_type == 0is.obs_extract_av1_headers: every OBU stays in the packet, and sequence header and metadata OBUs are also copied to the header. Empty outputs are NULL.metadata_obu: header byte, leb128 size, type, payload, then the0x80trailing bits.Motivation and Context
Plan: #45 (comment). With this, all four codec helpers (
obs-nal,obs-avc,obs-hevc,obs-av1) are ported.Refs #45
How Has This Been Tested?
Windows 11, MSVC 14.44, soldr 0.9.31.
Tier 3 (4096 cases each):
Keyframe results and both extract outputs are compared byte for byte.
metadata_obuand the T.35 wrapper are compared on random payloads and types, and at the leb128 size boundaries.C test expectations:
cmocka_cases_match_c_oraclecheckstest_av1.c's expectations against the oracle. Against master'sobs-av1.cit fails with a packet of 18 bytes for a 4-byte input; against the fixed file it passes.Mutation check: 11 mutants, 10 caught. The leb128 shift needed the big-payload generator. The survivor is equivalent:
size - 1without a size field, which the final cut reduces to the same value.Other checks:
soldr cargo test --workspace --locked(46 binaries),python ci/local_gate.py --lane lint, andcargo clippy -p obs-codec -p libobs-rust --lib -- -D warningsfor x86_64/aarch64 Linux and aarch64 macOS.Types of changes
Checklist:
🤖 Generated with Claude Code