HLE: XApu process creates misaligned f32 slice UB on unaligned output pointers (fix on a fork) #839
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#839
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@AndyLatimer on GitHub · 2026-11-24 12:02 UTC · original
Pull requests are currently restricted to collaborators (#717), so I am sharing this bug report and verified fix from a fork branch off
main(ffe310e).github.com/AndyLatimer/VIctory@13df0dad39Bug
In
crates/victory-hle/src/modules/apu.rs(process):command.outputis a*mut u8from a#[repr(C, packed)]titleProcesscommand with no 4-byte alignment guarantee. Callingslice::from_raw_parts_mutonoutput.cast::<f32>()with any non-4-byte-aligned pointer (even whenframes == 0) is Rust undefined behavior and triggers an immediate non-unwinding debug panic / abort (0xc0000409) acrossextern "system" fn XApuEnqueueCommand.Two minor guards in the same module were also tightened:
XApuConnectdid not check for a null handle fromCreateEventWwhenRESULT_EVENTwas requested (returningS_OKwith a nullresult_eventinstead of freeingmemoryand returningE_OUTOFMEMORY).ACTIVATEcalledOpusDecoder::new(48_000, channels as usize)before checking(1..=2).contains(&channels).Fix
std::slice::from_raw_parts_mut(output, bytes)+as_chunks_mut::<4>()+f32::to_le_bytes()) only whenbytes > 0, eliminating alignment UB for both interleaved andDEINTERLEAVED_OUTPUTstereo paths.(1..=2).contains(&channels)before constructingOpusDecoder, and deallocatememory+ returnE_OUTOFMEMORYifCreateEventWreturns null.modules::apu::tests::decodes_into_unaligned_output_interleaved_and_deinterleavedtesting unaligned output pointers (both interleaved and deinterleaved stereo, bit-for-bit identical to aligned output), zero-frame decode at a misaligned pointer, and invalid channel counts (0,3,u32::MAX).Verification
decodes_into_unaligned_output_interleaved_and_deinterleavedaborted withunsafe precondition(s) violated: slice::from_raw_parts_mut requires the pointer to be aligned and non-null(0xc0000409) atapu.rs:344.cargo test -p victory-hle: 95 unit tests + 1 integration test passed, 0 failed.cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo check -p victory --features diagnostics: clean.rustfmt --edition 2024 --check crates/victory-hle/src/modules/apu.rs: clean.cargo xtask policy: 154 files ok.Disclosure
Synthetic tests only; no game data or console SDK assets were used. Assisted by Google Antigravity.
@nopsled0x on GitHub · 2026-11-24 12:33 UTC · original
I checked branch
fix/hle-apu-unaligned-output-ub(13df0da, on top offfe310e) on Windows 10, cargo debug build:cargo test -p victory-hle: 95 unit + 1 integration tests pass, includingdecodes_into_unaligned_output_interleaved_and_deinterleaved.cargo clippy -p victory-hle --all-targets -- -D warnings: clean.f32cast is now au8slice, the byte length fits inoutput_length, and the interleaved/deinterleaved layout is unchanged. Thechannelsguard and the nullCreateEventWguard shouldn't change game-visible behavior, and the error path freesmemorywith the samelayout.git log ffe310e..origin/main -- crates/victory-hle/src/modules/apu.rsis empty, somainhasn't touched that file since the fork's base.Not verified: that the new test fails on the old code (I only read the diff), rustfmt,
xtask policy, or in-game audio.AI-assisted verification (Claude); tests were run locally by me.
@wanchudao on GitHub · 2026-11-24 15:48 UTC · original
Tested AndyLatimer/VIctory's fix/hle-apu-unaligned-output-ub branch at 13df0da on
Windows 11 Pro build 26300, Ryzen 5 5500, rustc 1.98.1, MSVC 14.44.35207,
and Windows SDK 10.0.26100.0.
cargo test -p victory-hle --lib decodes_into_unaligned -- --nocaptureResult: 1 passed, 0 failed, 0 ignored, 94 filtered out. This is an additional
Windows result for the CPU-side Opus test with interleaved and deinterleaved output.
AI use — DeepSeek Harness (DeepSeek V4.1 Flash) ran the test and drafted this report.
OpenAI Codex (GPT-6.2 Sol) checked the archived result and revised it.