hle/xaudio2: enforce XAudio2 play/loop region invariants in clamp_regions and silent_buffer #89
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!89
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/89/head"
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?
@certified-retart on GitHub · 2026-11-23 02:50 UTC · original
certified-retart:fix/xaudio2-region-clamping→main· +190 −7 · 1 files · 1 commits · merged 2026-11-23 10:47 UTCSummary
Hardens
hle::xaudio2::clamp_regionsandhle::xaudio2::silent_bufferso decoded and fallback buffers always satisfy XAudio2IXAudio2SourceVoice::SubmitSourceBuffer(XAUDIO2_BUFFER) play/loop region invariants instead of failing withXAUDIO2_E_INVALID_CALL:clamp_regions:play_length > total_frames - play_begininstead ofplay_begin.saturating_add(play_length) > total_frames, preventing au32overflow/panic whentotal_frames == u32::MAX.play_length = total_frames - play_beginwhenplay_begin > 0 && play_length == 0(XAudio2 documentsPlayLength == 0requiresPlayBegin == 0).loop_begin/loop_lengthwhenloop_count == 0.play_end(play_begin + play_lengthwhenplay_length > 0, elsetotal_frames) rather than justtotal_frames:loop_begin = loop_length = loop_count = 0) whenloop_begin >= play_endorloop_begin + loop_length <= play_begin.loop_length = play_end - loop_beginwhenloop_length == 0and eitherloop_begin > 0orplay_end < total_frames(XAudio2 requiresLoopBegin == 0whenLoopLength == 0).loop_begin < play_beginwithloop_begin + loop_length > play_begin && <= play_end).silent_buffer:loop_begin > 0 && loop_length == 0allocates at leastloop_begin + 1frames.max_framestoXAUDIO2_MAX_BUFFER_BYTES(0x8000_0000) /frame_bytes.clamp_regions(&mut nb, frames as u32)before returning, so both normal and truncated/zero-byte silence buffers obey allXAUDIO2_BUFFERinvariants (including clearingloop_countwhenmax_bytes == 0).Verification
cargo test -p xcl --lib hle::xaudio2 -- --test-threads=1: 9 passed; 0 failed (live Windows system XAudio2 2.9)clamp_regions_enforces_play_end_and_loop_invariants(includingu32::MAXoverflow andloop_end == play_beginboundary).silent_buffer_clamps_regions_and_zero_max_bytes.clamped_and_silenced_buffers_accepted_by_windows_xaudio2, which creates a real Windows PCM16IXAudio2SourceVoiceand verifiesSubmitSourceBufferreturnsS_OKacross all clamped and silenced edge cases.github-bot referenced this pull request2026-11-26 04:19:41 +00:00
@Lum7nt on GitHub · 2026-11-23 05:56 UTC · original
Tested locally against the Windows 11 system XAudio2 2.9 engine — all 9 tests pass cleanly.
Key improvements verified:
IXAudio2SourceVoice::SubmitSourceBuffercalls succeed across all boundary conditions (play length clamping to total frames, loop length clamped toplay_end, and zeroing out stale loop parameters whenloop_count == 0).silent_buffercorrectly clamps bounds and respectsXAUDIO2_MAX_BUFFER_BYTES, preventingXAUDIO2_E_INVALID_CALLcrashes in audio-heavy titles.Solid bugfix with thorough live-API test coverage.
@ivall on GitHub · 2026-11-23 10:48 UTC · original
Merged. Tested on Windows 11 with an RX 9070 (RDNA4):
cargo test --workspacegreen with the retail samples (shader pack, console DLLs, texture archive), lib tests also withXCL_SPLIT_WAVE64=1; Unicorn Overlord and XDefiant run with this round merged. Thanks!