e2e: destroy XAudio2 voices before dropping audio buffers on early errors #1871

Open
microwave805 wants to merge 1 commit from upstream-pr/1881 into main
microwave805 commented 2026-11-24 22:33:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-24T22:33:30Z.


In tests/testtitle/src/audio.rs, xaudio2_console_voices() submitted raw pointers to three heap Vec buffers (packet, samples, opus_block) to live XAudio2 source voices, then only destroyed those voices and released the engine at the end of the function. Any early return Err(...) (for example a voice creation error, SubmitSourceBuffer failure, or callback wait timeout) dropped the Vec buffers while Windows' XAudio2 audio thread was still reading them (use-after-free).

What is in it

  • tests/testtitle/src/audio.rs: declare the three submitted buffers before a new RAII AudioGuard that owns the engine, mastering voice, and source voice pointers; its Drop impl destroys every non-null source voice, destroys the mastering voice, and releases eng before the buffers are freed on every return or unwind path.

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 3070 (driver 32.0.16.1742), AMD Ryzen 5 5600X, Windows 11 Pro build 22631, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17, debug build.
  • cargo build -p xcl-testtitle: clean build, 0 warnings.
  • .\scripts\test.ps1 on exact head c320bf0 (builds xcl-testtitle and runs the e2e audio tests): 975 passed, 0 failed, 45 ignored (23 GPU tests SKIPPED on this adapter: 18 wave64 skips — 7 standalone no wave64 + 11 wave64 subcases — 3 pre-existing per-lane #1426 diffs, 1 no heap windows, 1 driver-cache disable requiring Windows Developer Mode; XCL_SAMPLE_* env vars unset).

Regression run
Not needed: this PR changes only tests/testtitle/src/audio.rs (no runtime code under crates/xcl/src).

Not tested

  • Forcing an XAudio2 error / timeout path inside xaudio2_console_voices() under a heap verifier.
  • AMD / Intel / native wave64 GPUs, Linux / Wine, and XCL_SAMPLE_* game-data tests.

AI use

  • Antigravity (Gemini 4 Neon): identified the early-return buffer UAF, implemented the RAII AudioGuard, ran .\scripts\test.ps1 on c320bf0, and drafted this description.
<!-- greyfinch-sync:ivall/xcl:issue:5481452580 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1881). Originally posted by [microwave805](https://github.com/microwave805) on 2026-11-24T22:33:30Z. --- In `tests/testtitle/src/audio.rs`, `xaudio2_console_voices()` submitted raw pointers to three heap `Vec` buffers (`packet`, `samples`, `opus_block`) to live XAudio2 source voices, then only destroyed those voices and released the engine at the end of the function. Any early `return Err(...)` (for example a voice creation error, `SubmitSourceBuffer` failure, or callback wait timeout) dropped the `Vec` buffers while Windows' XAudio2 audio thread was still reading them (use-after-free). **What is in it** - `tests/testtitle/src/audio.rs`: declare the three submitted buffers before a new RAII `AudioGuard` that owns the engine, mastering voice, and source voice pointers; its `Drop` impl destroys every non-null source voice, destroys the mastering voice, and releases `eng` before the buffers are freed on every return or unwind path. **Tested** - Hardware / toolchain: NVIDIA GeForce RTX 3070 (driver `32.0.16.1742`), AMD Ryzen 5 5600X, Windows 11 Pro build 22631, Rust `1.100.0` (`stable-x86_64-pc-windows-msvc`), DXC `1.9.2602.17`, debug build. - `cargo build -p xcl-testtitle`: clean build, 0 warnings. - `.\scripts\test.ps1` on exact head `c320bf0` (builds `xcl-testtitle` and runs the e2e audio tests): **975 passed, 0 failed, 45 ignored** (`23` GPU tests `SKIPPED` on this adapter: 18 wave64 skips — 7 standalone `no wave64` + 11 wave64 subcases — 3 pre-existing per-lane `#1426` diffs, 1 `no heap windows`, 1 driver-cache disable requiring Windows Developer Mode; `XCL_SAMPLE_*` env vars unset). **Regression run** Not needed: this PR changes only `tests/testtitle/src/audio.rs` (no runtime code under `crates/xcl/src`). **Not tested** - Forcing an XAudio2 error / timeout path inside `xaudio2_console_voices()` under a heap verifier. - AMD / Intel / native wave64 GPUs, Linux / Wine, and `XCL_SAMPLE_*` game-data tests. **AI use** - Antigravity (Gemini 4 Neon): identified the early-return buffer UAF, implemented the RAII `AudioGuard`, ran `.\scripts\test.ps1` on `c320bf0`, and drafted this description.
futurepro62 commented 2026-11-25 00:08:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T23:31:40Z.


Full-suite run, since this PR has no test report yet. Tested exact head c320bf0 (on its base 689f2db).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::dxil::fuzz_tests: 965 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • No new #[test] functions in the diff.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 925 passed, 1 failed, 25 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))).
  • On NVIDIA, --skip leaves out tests that fail on main 689f2db too, not because of this PR. heap_window_out_of_memory_falls_back_to_the_switch_form (#1651) and the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh. In gpu::dxil::fuzz_tests, seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card on main as well, with drivers 616.64 and 621.40. With fuzz_tests included, this PR showed the same 4 failures and no others (driver 616.64).
  • The AMD run does not set XCL_REQUIRE_GPU. Its one failure, gpu::dxil::fuzz_tests seed 540 (res[833] 0x7 vs CPU 0x6), happens on main 689f2db too.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7147500551 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1881#issuecomment-7147500551). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T23:31:40Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `c320bf0` (on its base `689f2db`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::dxil::fuzz_tests`: **965 passed, 0 failed, 43 ignored**. SKIPPED (no wave64): `a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu`, `a_per_lane_2d_or_3d_group_runs_on_the_gpu`, `coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu`, `cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu`, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`, `the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu`. - No new `#[test]` functions in the diff. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **925 passed, 1 failed, 25 ignored**. SKIPPED: `f16_programs_on_the_gpu` (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))). - On NVIDIA, `--skip` leaves out tests that fail on main `689f2db` too, not because of this PR. `heap_window_out_of_memory_falls_back_to_the_switch_form` (#1651) and the four `gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu` tests ([follow-up on #1651](https://github.com/xcl-dev/xcl/issues/1651#issuecomment-7146069648)) fail because `runner::skip_test` turns their skips into failures under `XCL_REQUIRE_GPU=mesh`. In `gpu::dxil::fuzz_tests`, seeds 70, 545, 1019 and 1507 fail `CreateComputePipelineState` with `E_OUTOFMEMORY` on this card on main as well, with drivers 616.64 and 621.40. With fuzz_tests included, this PR showed the same 4 failures and no others (driver 616.64). - The AMD run does not set `XCL_REQUIRE_GPU`. Its one failure, `gpu::dxil::fuzz_tests` seed 540 (`res[833]` 0x7 vs CPU 0x6), happens on main `689f2db` too. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
DavidM1911 commented 2026-11-25 02:09:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T01:56:47Z.


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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7150141802 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1881#issuecomment-7150141802). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T01:56:47Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
JJAutoCompare commented 2026-11-25 03:05:59 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T03:02:36Z.


PR #1881 test report

Tested upstream head c320bf083d. The diff changes only the synthetic test title's XAudio2 cleanup in tests/testtitle/src/audio.rs.

Tested

  • STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave size 8–32, DoublePrecisionFloatShaderOps=0). Rust 1.100.0 (0ef1bc386 2026-11-09) and DXC/DXIL 1.9.2609.5. Dev/test profiles had debug info and incremental compilation disabled.
  • cargo build --workspace and cargo test --workspace --no-run both exited 0. The synthetic title has zero standalone unit tests.
  • cargo test -p xcl --test e2e -- --show-output --test-threads=4 under the Arc lock exited 101 with 2 passed, 1 failed, 0 ignored. One nominal pass skipped the debug-layer check because d3d12SDKLayers.dll was missing. The synthetic title created a system XAudio2 2.9 engine, then CreateMasteringVoice returned 0x80070490. Its XAudio2 check printed PASS after taking the no-device early return, which skips all source voices. The e2e failure was the D3D12.X RSSetDepthBiasX pixel check (blue instead of green).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 ran once under the Arc lock and exited 101. The 20 result summaries in pr1881-suite.log total 950 passed, 25 failed, 45 ignored, with 22 SKIPPED lines. The harness pass total includes early returns, and a test can emit more than one skip line.
  • Failures comprised 20 GPU compute PSO creation errors (0x80070057), four GPU result mismatches (FMA contraction, sampled LOD, f16 half preservation, and wave reduction), and the same e2e depth-bias failure. Logged skips comprised 17 for missing wave64, three unsupported per-lane lowering cases, one for unavailable heap windows, and one for unavailable driver-cache control. The separate focused e2e log captured the debug-layer skip hidden by the full suite's default output capture.

Not tested

XMA2, PCM, and Opus source voices and cleanup after a buffer is submitted require an audio endpoint on this test path. D3D12 debug-layer validation, retail sample inputs, other GPUs, and a main-branch control run were outside this verification.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1881-suite.log and published this report.

<!-- greyfinch-sync:ivall/xcl:comment:7151532776 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1881#issuecomment-7151532776). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-25T03:02:36Z. --- # PR #1881 test report Tested upstream head c320bf083d1f33cda8b0c597734dad845b433d10. The diff changes only the synthetic test title's XAudio2 cleanup in tests/testtitle/src/audio.rs. **Tested** - STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave size 8–32, DoublePrecisionFloatShaderOps=0). Rust 1.100.0 (0ef1bc386 2026-11-09) and DXC/DXIL 1.9.2609.5. Dev/test profiles had debug info and incremental compilation disabled. - cargo build --workspace and cargo test --workspace --no-run both exited 0. The synthetic title has zero standalone unit tests. - cargo test -p xcl --test e2e -- --show-output --test-threads=4 under the Arc lock exited 101 with 2 passed, 1 failed, 0 ignored. One nominal pass skipped the debug-layer check because d3d12SDKLayers.dll was missing. The synthetic title created a system XAudio2 2.9 engine, then CreateMasteringVoice returned 0x80070490. Its XAudio2 check printed PASS after taking the no-device early return, which skips all source voices. The e2e failure was the D3D12.X RSSetDepthBiasX pixel check (blue instead of green). - cargo test --workspace --no-fail-fast -- --test-threads=4 ran once under the Arc lock and exited 101. The 20 result summaries in pr1881-suite.log total **950 passed, 25 failed, 45 ignored**, with **22 SKIPPED lines**. The harness pass total includes early returns, and a test can emit more than one skip line. - Failures comprised 20 GPU compute PSO creation errors (0x80070057), four GPU result mismatches (FMA contraction, sampled LOD, f16 half preservation, and wave reduction), and the same e2e depth-bias failure. Logged skips comprised 17 for missing wave64, three unsupported per-lane lowering cases, one for unavailable heap windows, and one for unavailable driver-cache control. The separate focused e2e log captured the debug-layer skip hidden by the full suite's default output capture. **Not tested** XMA2, PCM, and Opus source voices and cleanup after a buffer is submitted require an audio endpoint on this test path. D3D12 debug-layer validation, retail sample inputs, other GPUs, and a main-branch control run were outside this verification. **AI use** T3 Code / Codex (`gpt-6.2-sol`, `reasoningEffort: high`) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, `gemini-4-neon`) verified counts against `pr1881-suite.log` and published this report.
github-actions[bot] commented 2026-11-28 20:18:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T20:18:31Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7245190496 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1881#issuecomment-7245190496). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T20:18:31Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 07:02:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:02:49Z.


Triage (#1607) – head c320bf0

No open or merged PR touches tests/testtitle/src/audio.rs; the lines shared with #1437 are common XAudio2 call boilerplate, and #1437 only changes crates/xcl/src/hle/xaudio2.rs. Declaring packet/samples/opus_block before AudioGuard does make the voices and engine go away before the buffers on every early return Err.
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.

<!-- greyfinch-sync:ivall/xcl:comment:7303582512 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1881#issuecomment-7303582512). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:02:49Z. --- **Triage (#1607)** – head c320bf0 No open or merged PR touches `tests/testtitle/src/audio.rs`; the lines shared with #1437 are common XAudio2 call boilerplate, and #1437 only changes `crates/xcl/src/hle/xaudio2.rs`. Declaring `packet`/`samples`/`opus_block` before `AudioGuard` does make the voices and engine go away before the buffers on every early `return Err`. 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1881:upstream-pr/1881'
git switch 'upstream-pr/1881'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1881'
git switch 'upstream-pr/1881'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1881'
git switch 'upstream-pr/1881'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1881'
git switch 'main'
git merge --squash 'upstream-pr/1881'
git switch 'main'
git merge --ff-only 'upstream-pr/1881'
git switch 'main'
git merge 'upstream-pr/1881'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1871
No description provided.