Skip to content

XAudio2: validate Opus decoded channel limit - #1458

Open
hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/opus-decoded-channel-limit
Open

hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/opus-decoded-channel-limit

Conversation

@hajduzsolt

@hajduzsolt hajduzsolt commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What is in it

  • What is in it
  • Reject Opus headers whose stream and coupled counts exceed the 255 decoded-channel limit in RFC 7845.
  • Add synthetic tests for a valid 255-channel boundary and invalid 256- and 510-channel totals.

Tested

  • Windows 11 Pro x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT 16 GB (driver 32.0.32029.2010), Rust 1.98.1 MSVC, debug. - cargo test -p xcl --lib opus_head_rejects_more_than_255_decoded_channels: fails without the guard and passes with it (1 passed, 0 failed). - cargo test --workspace -- --test-threads=4 --nocapture: 771 passed, 0 failed, 41 ignored. Two tests counted as passed reported SKIPPED because the D3D12 debug layer was unavailable: test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state.

Regression run

main:

xcl-smoke v1
commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1677 (PresentX 1677)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14837 MB

PR:

xcl-smoke v1
commit: afaca49b5ca96c66a590b67bc8e5eeb88db941d0
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1679 (PresentX 1679)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14830 MB

Not tested

  • Extended multi-hour gameplay beyond the 60-second smoke run and online Xbox Live features (XCL_NETWORK=0).

AI use

  • GPT-6 wrote the implementation and synthetic unit tests. Human review and smoke verification are pending.

Reject mapping headers whose stream and coupled counts exceed the RFC limit before creating decoder state.

Co-Authored-By: Codex GPT-6 <noreply@openai.com>
@hajduzsolt
hajduzsolt marked this pull request as ready for review November 24, 2026 16:52
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@Belox17

Belox17 commented Nov 24, 2026

Copy link
Copy Markdown

Test report for afaca49b on NVIDIA (RTX 3060 Ti): passes on NVIDIA too, and the test fails without the fix

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB (32-lane waves), driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug build. Head afaca49b as is (base b7aa9f3), clean tree.
  • The new test (opus_head_rejects_more_than_255_decoded_channels) with cargo test -p xcl --lib <name>: 1 passed.
  • cargo test --workspace -- --test-threads=4 on the head: 771 passed, 0 failed, 41 ignored; its base b7aa9f3 on the same machine: 770 passed, 0 failed, 41 ignored. SKIPPED on both: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • Merged into current main c160d86e (clean merge): 859 passed, 0 failed, 42 ignored; main alone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above.
  • With the check in hle/opus.rs reverted (test kept), the test fails: assertion failed: parse_opus_head(&head).is_none().

Not tested

  • AMD / native wave64 hardware; any retail title (no smoke run).

AI use: Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

NVIDIA test report for afaca49: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug. Head tested as-is on its base b7aa9f3.

  • cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4: 714 passed, 0 failed, 21 ignored; 2 SKIPPED (no wave64), not in this PR's files.
  • cargo test -p xcl --lib -- --exact hle::opus::tests::opus_head_rejects_more_than_255_decoded_channels --test-threads=1 --nocapture, 3 runs: 3/3 passed, 0 SKIPPED.
    Lib tests only; no title run.
    AI-assisted (Claude Code, Claude Opus 5.5).

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #1458 at head afaca49b5ca96c66a590b67bc8e5eeb88db941d0 (1 commit; exact parent & merge-base: b7aa9f3bd212088e0d927439284dc5ed325ce3c7, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, Wave32-only Ada), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted tests & build (afaca49b)

Command Result
cargo test --release -p xcl --lib opus_head_rejects_more_than_255_decoded_channels -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 743 filtered out × 3 (0.00s, 0.00s, 0.00s, 0 skipped)
cargo test --release -p xcl --lib hle::opus:: -- --nocapture (3 consecutive runs) 14 passed; 0 failed; 0 ignored; 730 filtered out × 3 (0.00s, 0.00s, 0.00s; 13 executed incl. live Windows Media Foundation MSOpusDecoder, 1 self-skipped on decodes_a_game_sound because XCL_SAMPLE_AWC was unset)
cargo build --release -p xcl Clean build (1m 03s, exit 0, 0 new warnings in opus.rs)

Paired quiet 60 s retail smoke (title: 29640639)

(Note: scripts/smoke.ps1 at b7aa9f3b predates 9683e7a6 and printed the local folder basename on title:; replaced below with the standard 9683e7a6 title hash 29640639, with all measured fields verbatim.)

Exact parent & merge-base (b7aa9f3bd212088e0d927439284dc5ed325ce3c7):

xcl-smoke v1
commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1598 (PresentX 1599)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14719 MB

PR #1458 (afaca49b5ca96c66a590b67bc8e5eeb88db941d0):

xcl-smoke v1
commit: afaca49b5ca96c66a590b67bc8e5eeb88db941d0
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1545 (PresentX 1545)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14724 MB

Limits of coverage

  • opus_head_rejects_more_than_255_decoded_channels and 13/14 active hle::opus:: tests (including Windows Media Foundation MSOpusDecoder; 1 test decodes_a_game_sound self-skipped with XCL_SAMPLE_AWC unset) passed 3/3.
  • The 60 s retail smoke confirms steady 60 Hz runtime non-regression (0 device removals, 0 crashes); single-run frame/commit delta vs. parent reflects normal startup variance.

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

@BBareth

BBareth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check claim
head: afaca49

@github-actions github-actions Bot added area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 30, 2026
@BBareth

BBareth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: afaca49
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails on the base alone too (base: 2885 passed, 1 failed, 51 ignored, 28 SKIPPED lines). 28 SKIPPED lines, as on the base. The new test hle::opus::tests::opus_head_rejects_more_than_255_decoded_channels passed, as did the existing opus tests.
review: no blocking finding; one file, every hunk read. parse_opus_head (channel mapping family other than 0) now returns None when streams + coupled streams exceed 255, the RFC 7845 limit for the decoded channel count, before the mapping table is checked against it. The test pins both sides: 128 + 127 = 255 is accepted, 129 + 127 and 255 + 255 are refused. No caller behaviour changes for valid headers.
performance: none: one comparison per header parse.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 30, 2026
@tiagonleal

tiagonleal commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: afaca49
merge: clean, alone and together with #1446 (a7f5d8b) and #1451 (58b4e75): the three heads merged onto the base in one tree (c48c9d04) without conflicts, #1451 included although it edits the same file; also no conflict between that tree and #926 (open, touches opus.rs but not parse_opus_head)
build: cargo build --workspace -> ok on the combined tree (also cargo build --release -p xcl)
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 on the combined tree of the three heads above on the base (one suite run for the three PRs, not one per PR) -> 2888 passed, 1 failed, 51 ignored; SKIPPED: 24 lines, the same as on the base; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails the same way on the base alone (2885 passed, 1 failed, 51 ignored; #3513 fixes it). hle::opus::tests::opus_head_rejects_more_than_255_decoded_channels ran and passed. With the new check replaced by if false, it fails at opus.rs:1781; file restored after.
review: one file, whole diff read. What this adds to the first check: when parse_opus_head refuses a head, the caller does not fail. Decoder::new (opus.rs:1470) falls back to a head built from the voice's own channel count, clamped to 1..=8 (opus.rs:1472-1478), so an XAudio2 Opus voice whose extra bytes carry more than 255 decoded channels (xaudio2.rs:939) is now decoded with the default mapping for its channel count instead of the title's head. The other caller, the Ogg reader (opus.rs:665), treats None as no head. The 255 bound is the RFC 7845 limit on streams plus coupled streams. A tighter check is still missing: the header itself allows at most 8 output channels (opus.rs:488), yet a head with, say, 255 streams and 0 coupled still passes and makes 255 single-stream decoders (opus.rs:1488-1492); that was so before and is outside this PR. The emulator's own APU decoder passes no head (acphal.rs:793), so it always takes the default path.
performance: scripts/smoke.ps1, 60 s of a retail title, release, combined tree of the three heads: 1597 frames and 17767 MB peak commit against 1659 frames and 17322 MB on the base (today's base run after one warm-up; a later traced base run gave 1670 frames, 18142 MB). No device removal, no crash. Audio initialised as on the base: the same acphal and xapu lines; neither run logs an XAudio2 Opus voice or an Opus decoder choice, so the title sends no Opus head in its menus and nothing was rejected that the base accepted. I did not rerun to see whether the lower frame count repeats.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5 ran the build, suite, tests and smoke, reviewed the diff against the merged source and wrote this)

  • Tiago

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head afaca49

No open or merged PR makes the same change, and main's parse_opus_head still has no stream_count + coupled_count <= 255 check (RFC 7845 5.1.1). The test covers the 255 boundary and two invalid totals. No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants