Skip to content

fix(media-io): decompress_422 converts one row, in the C and the Rust (#3031) - #3073

Merged
zackees merged 3 commits into
masterfrom
fix/3031-decompress-422-rows
Oct 30, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/3031-decompress-422-rows

Conversation

@vpacher

@vpacher vpacher commented Oct 30, 2026

Copy link
Copy Markdown
Member

Fixes #3031

What and why

decompress_422() (exported in format-conversion.h) converted twice each row. A packed 4:2:2 row (UYVY or YUY2) has 2 bytes per pixel, so in_linesize bytes are in_linesize / 4 32-bit words; the C and the Rust took min(in_linesize, out_linesize) / 2. Each row read twice its bytes and wrote twice its output row, and the last rows of a frame ran past the caller's buffers. Nothing in OBS calls it (upstream removed the CPU YUV path, e5b004f); a plugin that calls it with its own frame buffers is affected (low tier under SECURITY.md).

Per the decision on #3031 (#3031 (comment)), the C and the Rust change together, by the same line (/ 2 to / 4):

  • libobs/media-io/format-conversion.c.h
  • rust/obs-media-io/src/format_conversion.rs

The C oracle includes the production file, so Tier 3 stays byte-exact and rust/README.md gets no intentional difference; its "quirks kept" note for the spill goes.

Commits

  1. RED 8565aac: a new exact-size case, one row in (in_linesize 8, followed by the next row's first 2 dwords) and one row out (out_linesize 16), in three tiers:

    • Tier 2: test_decompress_422_one_row in test/cmocka/test_format_conversion.c (new; hybrid libobs and the C reference);
    • Tier 1: its Rust mirror;
    • Tier 3: decompress_422_one_row, the native C, the scalar C, the safe core and the shim against the expected bytes.

    It fails in every implementation on master: each one reads the next row and writes 16 bytes past the output row. The canary differs from byte 16 on, with no out-of-bounds access, because the buffers have 16 bytes of canary slack.

  2. Characterization cases 2de855b: only the two cases the decision names, in their own commit, which cites the decision:

    • test_decompress_422_literals: 1 dword in, 2 out, the rest canary;
    • test_decompress_422_rows_spill is renamed test_decompress_422_rows_in_bounds: 2 rows read 4 of 6 dwords and write 8.

    No other assertion in the file changes. The Tier 1 Rust mirror of the two cases changes the same way.

  3. GREEN f224c6e:

    • / 4 in both implementations;
    • the parity test sizes its buffers by / 4, so every proptest case runs on buffers of exactly the converted rows;
    • the Tier 1 wrap case expects 2 words;
    • the port_comparison bench sizes one frame;
    • README and ledger lines.

Tests

  • macOS (aarch64, the simde oracle): format_conversion 32/32 on GREEN. RED: decompress_422_one_row (Tier 1 and Tier 3) fails. Tier 3 fails first on the native C.
  • Linux gate host, stamped head f224c6e: lint, rust-test, cross (Windows and macOS clippy and Dylint) and tier2-linux (test_format_conversion against the hybrid libobs and the C reference) passed, 439 s.
  • port_comparison ^format/ in Criterion --test mode: every case passes, with frame-sized decompress_422 buffers.
  • Real app: N/A (no caller in OBS).
  • Test cost: three small cases, well under 0.1 s; no own threads.

The recorded port_comparison baselines in docs/rust-port/benchmarks/ keep their decompress_422 timings. Those timings measure the old double row on both sides, so the Rust/C ratio stays comparable. The next recording halves both.

Upstream obsproject/obs-studio has the same line. Any report there goes to the maintainer (decision point 4).

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • User-visible change: line in docs/features.md
  • (Optional) Local gate passed and the pushed head is stamped
  • Warning or flag changes: not applicable
  • Intentional differences from C: none (both changed)

🤖 Generated with Claude Code

vpacher and others added 3 commits October 30, 2026 15:00
…uffers (#3031)

One packed 4:2:2 row of 4 pixels (in_linesize 8), followed by the next
row's first 2 dwords, into one row of 4 32-bit pixels (out_linesize 16).
The row must convert alone: no read of the next row, no write past the
16-byte output.

- test/cmocka/test_format_conversion.c: test_decompress_422_one_row (new,
  Tier 2: hybrid libobs and the C reference).
- Tier 1 mirror: test_decompress_422_one_row.
- Tier 3: decompress_422_one_row runs the native C, the scalar C, the
  safe core and the shim on the same buffers against the expected bytes.
  Packed::call is the old Packed::check closure, shared by both.

Fails on master in every implementation: min(in_linesize, out_linesize) / 2
converts 4 dwords, so the next row is read and the output gets 16 bytes
past its row (the canary differs from byte 16 on).

Refs #3031

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cterization cases (#3031)

Per the decision on #3031 (#3031 (comment)):
fix the C and the Rust together and update the two characterization cases
of test/cmocka/test_format_conversion.c to the corrected rows. They were
marked "Characterized, not endorsed" and pinned the double row.

- test_decompress_422_literals: in_linesize 4, out_linesize 8 converts 1
  dword into 2; the second input dword is not read and output dwords 2 and
  3 keep the canary.
- test_decompress_422_rows_spill is now test_decompress_422_rows_in_bounds:
  two rows of in_linesize 8 read 4 of the 6 dwords and write 8, the rest of
  the output keeps the canary.

No other assertion in the file changes. The Tier 1 Rust mirror of the two
cases changes the same way. Both fail until the GREEN commit.

Refs #3031

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…#3031)

A packed 4:2:2 row has 2 bytes per pixel, so in_linesize bytes are
in_linesize / 4 32-bit words. min(in_linesize, out_linesize) / 2 converted
twice that: each row read twice its bytes and wrote twice its output, and
the last rows of a frame ran past the caller's buffers.

Per the decision on #3031, both implementations change by the same line:
- libobs/media-io/format-conversion.c.h: / 4.
- rust/obs-media-io/src/format_conversion.rs: / 4; the doc no longer
  describes the spill as kept.

The C oracle includes the production file, so Tier 3 stays byte-exact; the
parity test sizes its buffers by / 4 now, so every proptest case runs on
buffers of exactly the converted rows. The Tier 1 wrap case
(decompress_422_row_offset_wraps_like_c) now expects 2 words and the
canary after them. rust/README.md drops the "quirks kept" note, the
port_comparison bench sizes one frame, and docs/features.md gets the line.

Fixes #3031

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=7dad87970600d8ed96ab07db1e6701bae729a2d5 secs=439 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793369524,"gate":"rust/all/fmt","host":"linux-x86_64","key":"906bc270a6079654822d78db12eb3de3a01e403491025a173b5949bea664133f","lane":"lint","parents":["2de855be9cd50096e3f856004f117986b332e347"],"secs":88,"stamp":"af199ff09d9f55be5ef238470fd30406","tree":"7dad87970600d8ed96ab07db1e6701bae729a2d5","v":1,"via":"run"}
Ci-Attestation: {"at":1793369524,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"906bc270a6079654822d78db12eb3de3a01e403491025a173b5949bea664133f","lane":"lint","parents":["2de855be9cd50096e3f856004f117986b332e347"],"secs":88,"stamp":"aab414dee0b96545a30b7ea665df195f","tree":"7dad87970600d8ed96ab07db1e6701bae729a2d5","v":1,"via":"run"}
Ci-Attestation: {"at":1793369524,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"d6670a0afcde730c504f436047736c508321e25bd02d1527e199527b8036a717","lane":"rust-test","parents":["2de855be9cd50096e3f856004f117986b332e347"],"secs":206,"stamp":"72fe0e3dec8def1decfad55be50c823a","tree":"7dad87970600d8ed96ab07db1e6701bae729a2d5","v":1,"via":"run"}
Ci-Attestation: {"at":1793369524,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"09bbab540c315635dabd031bd8d4b9161af0e44733dc8d5bcabbb3b6156f0fee","lane":"cross","parents":["2de855be9cd50096e3f856004f117986b332e347"],"secs":144,"stamp":"2f3aaa3e45fc7f0fdf7a33ea211ccefe","tree":"7dad87970600d8ed96ab07db1e6701bae729a2d5","v":1,"via":"run"}
Ci-Attestation: {"at":1793369524,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"09bbab540c315635dabd031bd8d4b9161af0e44733dc8d5bcabbb3b6156f0fee","lane":"cross","parents":["2de855be9cd50096e3f856004f117986b332e347"],"secs":144,"stamp":"35e2205223b891f07d5b384d616c37f5","tree":"7dad87970600d8ed96ab07db1e6701bae729a2d5","v":1,"via":"run"}
Ci-Attestation: {"at":1793369524,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"09bbab540c315635dabd031bd8d4b9161af0e44733dc8d5bcabbb3b6156f0fee","lane":"cross","parents":["2de855be9cd50096e3f856004f117986b332e347"],"secs":144,"stamp":"47c8cc3eb50cfeca784053561e94edce","tree":"7dad87970600d8ed96ab07db1e6701bae729a2d5","v":1,"via":"run"}
Ci-Attestation: {"at":1793369524,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"09bbab540c315635dabd031bd8d4b9161af0e44733dc8d5bcabbb3b6156f0fee","lane":"cross","parents":["2de855be9cd50096e3f856004f117986b332e347"],"secs":144,"stamp":"ff7fdd0ce9795cebe236db19f9b79c0f","tree":"7dad87970600d8ed96ab07db1e6701bae729a2d5","v":1,"via":"run"}
Ci-Attestation: {"at":1793369524,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"92b6ad32c194344dfde07167da28705e1d78026b69b858e3129877346b3bf406","lane":"tier2-linux","parents":["2de855be9cd50096e3f856004f117986b332e347"],"secs":247,"stamp":"77c5466342e0407bf42a70df1d93f176","tree":"7dad87970600d8ed96ab07db1e6701bae729a2d5","v":1,"via":"run"}
@vpacher
vpacher requested a review from zackees as a code owner October 30, 2026 14:13
@vpacher
vpacher enabled auto-merge October 30, 2026 14:15
@zackees
zackees disabled auto-merge October 30, 2026 14:23

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review. The code is correct: / 4 in the C and the Rust, the new one-row cases pass with canaries after the output, parity stays byte-exact across C, C-scalar, shim and safe, and the features line is in.

I turned auto-merge off, and I'm holding this for the maintainer for one reason. It edits an existing C test (test/cmocka/test_format_conversion.c: two assertions in test_decompress_422_literals, and test_decompress_422_rows_spill renamed and changed). AGENTS.md says not to edit existing C tests, and the #3031 decision that allows it was made by the coordinator, not the maintainer. Mitigating: that file is our own characterization test (added 2026-10-10 in 64978ca, not upstream), and the cases it changes were marked "characterized, not endorsed". So I expect a quick yes. Once the maintainer answers on #3031 I'll queue it, or ask for the Rust-only variant.

@zackees
zackees added this pull request to the merge queue Oct 30, 2026
Merged via the queue into master with commit cb277a0 Oct 30, 2026
37 checks passed
@zackees
zackees deleted the fix/3031-decompress-422-rows branch October 30, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

media-io: decompress_422() converts twice the row it is given

2 participants