Repository navigation
Description
What
decompress_422() (libobs/media-io/format-conversion.c.h:239, exported in format-conversion.h) converts twice the row it is given. Found while sizing the benchmark buffers for #3003 (#3029).
uint32_t width_d2 = min_uint32(in_linesize, out_linesize) / 2;
...
input32_end = input32 + width_d2; /* width_d2 32-bit words */
...
output32[0] = dw; ... output32[1] = dw; output32 += 2; /* 8 bytes per word */With linesizes in bytes, a packed 4:2:2 row (UYVY or YUY2) of W pixels has in_linesize = 2 * W. Each 32-bit input word holds 2 pixels, so a row is W / 2 words. min(2 * W, out_linesize) / 2 is W words: the loop reads 4 * W bytes per row (twice the row) and writes 8 * W bytes (twice an output row of W UYVX pixels). On the last rows of a frame it reads and writes past the buffers.
decompress_nv12() uses the same min(...) / 2 and is correct there: an NV12 luma row has 1 byte per pixel, and each step converts 2 pixels. Only the 4:2:2 variant has 2 bytes per pixel. / 4 would be one row.
The line comes from upstream OBS and is unchanged since at least 2019 (f53df7d, a clang-format reflow). The Rust port mirrors it (rust/obs-media-io/src/format_conversion.rs:317), as the Tier 3 parity test requires; format_conversion_parity.rs sizes its buffers by the same formula.
Example, 1080p UYVY: in_linesize = 3840, out_linesize = 7680, so width_d2 = 1920 words: 7680 bytes read from a 3840-byte row, 15360 bytes written to a 7680-byte row. On x86 the #3003 bench crashed with SIGSEGV until its buffers were sized by this formula; on macOS it did not crash.
Impact
Low. No caller in OBS: the CPU YUV conversion was removed upstream (e5b004f, "libobs: Remove YUV transformation on CPU"). Only a third-party plugin that calls the exported function is affected, with its own frame buffers (trusted local input), so this is a normal public bug per SECURITY.md.
Options
- Fix it in the Rust (
width_d2 = min(in_linesize, out_linesize) / 4for the packed input), and list it as an intentional difference from the C in the parity test header andrust/README.md. The parity test then checks the fixed rows against a corrected expectation instead of the oracle for this one function. - Keep the C behaviour for compatibility and document it in
format-conversion.h(the linesize a caller must pass for one row). - Report it upstream as well, since the C is unchanged there.
A plugin that relies on the current behaviour would have to pass half the real linesize; that seems unlikely, but it is the reason to decide 1 or 2 explicitly.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
vpacher commentedon Oct 30, 2026
Decision needed: which of the three options above. Recommendation: 1 (fix the row count in the Rust,
/ 4for the packed input, and list it as an intentional difference from the C in the parity test header andrust/README.md), plus 3 (report it upstream). No caller in OBS depends on the current behaviour, and a plugin would have to pass half its real linesize to rely on it. We can take the fix once this is decided.zackees commentedon Oct 30, 2026
Decided: option 1. Fix the row count in the Rust (
/ 4for the packed 4:2:2 input) as an intentional difference from the C, recorded in the parity test header andrust/README.md. Option 3 (reporting it upstream) goes to the maintainer, since it means contacting an outside project.Reasons:
format-conversion.h, which AGENTS.md forbids ("never edit public C headers to make a port pass"), and it would keep the overrun.For the fix PR: RED is a parity case with exact-size buffers (one row in, one row out) that overruns on the current Rust, under ASan or with a guard page. GREEN is
/ 4, with that case checked against the corrected expectation, plus the README and test-header entries. The C oracle stays as it is.vpacher commentedon Oct 30, 2026
Claiming: #3031, per the
Decided:above (option 1). After #3025, which I am finishing now.Plan (one PR, RED then GREEN):
rust/obs-media-io/tests/video/format_conversion_parity.rswith exact-size buffers (one packed 4:2:2 row in, one UYVX row out, a guard after each). It fails on the current Rust, which reads and writes past them.width_d2 = min(in_linesize, out_linesize) / 4for the packed input inrust/obs-media-io/src/format_conversion.rs; the case checks the corrected expectation instead of the oracle. The intentional difference goes into the parity test header andrust/README.md; the C oracle stays as it is.Draft PR within 48 h.
vpacher commentedon Oct 30, 2026
Before I write code: the
Decided:above cannot be built as written, because of a Tier 2 test.decompress_422ships from Rust:libobs/cmake/rust-exports.d/obs-media-io-format_conversion.txtexports all six conversions in the hybrid libobs.test/cmocka/test_format_conversion.c(added 2026-10-10 in 64978ca as a characterization test) pins the double row:test_decompress_422_literalsexpects 2 dwords read and 4 written forin_linesize4, andtest_decompress_422_rows_spill("Characterized, not endorsed") expects the spill into the next row.Decision needed: how to fix it under that test. Options:
/ 4inlibobs/media-io/format-conversion.c.hand inrust/obs-media-io/src/format_conversion.rs, and update the two characterization tests to the corrected rows, so they pass in both Tier 2 modes. The oracle includes the production file, so Tier 3 parity stays byte-exact and no intentional difference from our C is needed. The repo fixes C code (libobs: Keep the Wayland keymap if one won't load #2976, fix(libobs): only destroy the audio mutexes obs_init_audio created (#2910) #2911); the exception is the edit of the two tests, which pin a bug that this decision ends.GREEN for 1 would be: RED with exact-size buffers (one row in, one row out) as you described, failing on both the C and the Rust; then
/ 4in both, the two cmocka tests updated, and Tier 2 passing in both modes.github-actions commentedon Oct 30, 2026
Claim bot: @vpacher, the decision is in; your claim is no longer blocked.
vpacher commentedon Oct 30, 2026
The claim bot's message above quotes the
Decided:of 09:12, which came before the Tier 2 question of 09:58; that question is still open (labelsdecision-neededandclaim-blockedstay). @zackees, an answer withDecided:on the options in my comment of 09:58 would settle it.vpacher commentedon Oct 30, 2026
The claim-bot misfire above is filed as obs-rust/.github#22 (with the #2593 instance).
zackees commentedon Oct 30, 2026
Decided: option 1 from the 09:58 comment. Fix the C and the Rust together (
/ 4inlibobs/media-io/format-conversion.c.hand inrust/obs-media-io/src/format_conversion.rs), and update the two characterization cases intest/cmocka/test_format_conversion.cto the corrected rows. This replaces the "Rust only, intentional difference" part of my decision at 09:12, which did not account for this Tier 2 test.Reasons:
rust/README.mdgains no intentional-difference entry.Conditions for the PR, so the test edit can be audited:
test_decompress_422_literals,test_decompress_422_rows_spill), in a separate commit whose message cites this decision. Keep their names, or rename them to say they pin the corrected row. Change no other assertion in the file./ 4in both implementations, Tier 2 passing in both modes, and Tier 3 byte-exact.fix(media-io): decompress_422 converts one row, in the C and the Rust (…
perf(media-io): read a decompress row once instead of per pixel (#3111)
perf(media-io): read a decompress row once instead of per pixel (obs-…