HLE/apu: avoid unaligned &mut [f32] slice UB in Opus PCM output and validate channels #567
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!567
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-567"
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?
@AscilCH on GitHub · 2026-11-25 02:17 UTC · original
AscilCH:fix/hle-apu-unaligned-pcm-output-write→main· +126 −10 · 1 files · 1 commits · openProblem
In
crates/victory-hle/src/modules/apu.rs:*mut f32slice creation UB (process()):Process::outputis an arbitrary*mut u8from a#[repr(C, packed)]command struct.process()unconditionally constructedstd::slice::from_raw_parts_mut(output.cast::<f32>(), frames * channels)without checking 4-byte alignment — immediate Rust UB (and a debug-precondition abort across FFI) wheneveroutput as usize % 4 != 0.OpusDecoder::new:ACTIVATEpassed arbitrarychannels as usizedirectly intoOpusDecoder::newbefore checking(1..=2).contains(&channels).CreateEventWfailure: WhenRESULT_EVENTwas requested andCreateEventWreturned null,XApuConnectstill returnedS_OKwith a null event handle.Fix
ptr::copy_nonoverlappingand deinterleaved stereo PCM viaptr::write_unaligned, avoiding&mut [f32]creation over title*mut u8pointers.channelsbefore callingOpusDecoder::new.memoryand returnE_OUTOFMEMORYifCreateEventWreturns null whenRESULT_EVENTis set.unaligned_output_buffer_writes_interleaved_and_deinterleaved_pcm_safely.Verification
cargo test -p victory-hle --locked apu::tests: 2 passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-hle --all-targets --locked -- -D warnings: cleancargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic unit tests only, no game data.)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.