XAudio2: use saturating_mul for avg_bytes in pcm16_for_rate #1239
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1249"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T13:44:14Z.
pcm16_for_ratecomputedrate * block as u32without overflow checks. A malformed voice format with a large sample rate (e.g. 8 channels andrate >= 0x1000_0000) panicked in debug builds (aborting across theextern "system" fnboundary inCreateSourceVoice) and wrapped to a bogusavg_bytesin release builds.This switches
avg_bytestorate.saturating_mul(block as u32).What is in it
crates/xcl/src/hle/xaudio2.rs: userate.saturating_mul(block as u32)inpcm16_for_rate; add unit testpcm16_for_rate_saturates_avg_bytes_on_overflow(panicked on multiplication overflow before the fix).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib pcm16_for_rate_saturates_avg_bytes_on_overflow: 1 passed, 0 failed (panicked with multiplication overflow before the fix)Regression run
main:
PR:
Not tested
AI use
xaudio2.rs, wrote the fix and regression test, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:02:08Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Thanks!
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-27T21:26:34Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:20:28Z.
merge-check claim
head:
456c32dec7Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:28:24Z.
merge-check
base:
d0832e614fhead:
456c32dec7merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, same run: 2890 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache). The new test
pcm16_for_rate_saturates_avg_bytes_on_overflowran and passed.review: no blocking finding; one file (+11/-1), read.
pcm16_for_ratecomputesavg_byteswithsaturating_mulinstead of*, so a format with an absurd sample rate no longer overflows (a panic in a debug build, a wrapped value in release); every rate a real title uses gives the same value as before (the test checks 48 kHz stereo = 192,000). The new test fails without the change in a debug build by construction (8 channels at 0x2000_0000 Hz overflows u32).performance: none: one multiplication when a voice format is built.
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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:14:19Z.
Triage (#1607) – head
456c32dNo open or merged PR makes the same one-line change. #1437 removes the same overflow another way, by clamping the rate to 11 025–192 000 Hz in
pcm16_for_rate(along with much more), and conflicts with main; if it lands, this change becomes unnecessary.The change is correct: a title format with a rate above ~33.5 MHz (via
xma_info) overflowedrate * block(panic in debug, wrap in release). The resultingavg_bytes = u32::MAXvoice will still be rejected by Windows, which is fine.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T10:19:59Z.
merge-check
base:
1c8b551475head:
456c32dec7merge: clean (trial-merge commit 6768060cdd20637a9adca56a4db6f74841d26345, git diff --check clean)
build: cargo build --workspace ok
tests: 43 targets combined: 2910 passed, 0 failed, 51 ignored (+1 new test vs main baseline). Specifically, all 42 non-lib workspace targets under
cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapturepassed 148/0 (20 ignored, including gpu_two_pass_cache_e2e), andcargo test -p xcl --lib -- --test-threads=2passed 2762/0 (31 ignored;--test-threads=4hit the unrelated pre-existing ASLR collision on synthetic pointer 0x7c000041 in main's set_pipeline_state_goes_into_a_run_only_with_a_two_pass_pipeline -> real.rs:1237). Targeted new test hle::xaudio2::tests::pcm16_for_rate_saturates_avg_bytes_on_overflow passed with 0 skips. 28 SKIPPED lines (host environment only: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache (Windows Developer Mode required)).review: Read the full merged diff (+11/-1 in crates/xcl/src/hle/xaudio2.rs). Replaces
rate * block as u32withrate.saturating_mul(block as u32)inpcm16_for_rate, avoiding debug arithmetic overflow panics or release wraparound when computingavg_bytesfor extreme sample rates. The new unit test covers both normal(2, 48_000) -> 192_000and overflowing(8, 0x2000_0000) -> u32::MAXusing safe value copies from the packedWaveFormatExstruct. Minimal, exact, no scope creep or UB.performance: not applicable (Tier 1 — single-line saturation fix in
pcm16_for_rate, off hot rendering/GPU paths).verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
Imported from ivall/xcl. Originally posted by cj-tomlin on 2026-12-02T16:45:35Z.
Test report, head
456c32dec710ae1bc53f511e4ef50cc5ed8f8778merged ontomain5eaadb54c14e0fc29597b2a1689d7dbd83491303(clean, merge4fe5165e).cargo build --workspace: ok.cargo test --workspace --no-fail-fast -- --test-threads=4: 2975 passed, 0 failed, 52 ignored; SKIPPED: 27 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll), the same 27 as plainmain(2974 passed, 0 failed, 52 ignored) on this machine.pcm16_for_rate_saturates_avg_bytes_on_overflowpasses, and fails withattempt to multiply with overflow(xaudio2.rs:389) when I putmain'srate * block as u32back into the merged tree.Diff read (+11/-1,
xaudio2.rs), CPU only.Tool and model: Claude Code (Claude Opus 5.5) merged, built, ran the tests and drafted this; I checked it.