audio: XMA decoder slices can outlive ApuFree (use-after-free when a title frees live APU memory) #230

Open
opened 2026-11-26 12:15:59 +00:00 by github-bot · 0 comments
Owner

@⁠kekonn on GitHub · 2026-11-26 12:10 UTC · original

In crates/victory-hle/src/modules/audio.rs, heap_bytes (183) returns &'a mut [u8] with an unbound lifetime after the HEAP guard is dropped. The decoder thread writes output blocks through it (~541-548) and reads input packets (~611-623). heap_free (125) removes the block from the map and immediately calls std::alloc::dealloc, with no synchronisation against the decoder.

When: only if the title calls ApuFree on a voice's ring or input buffer while the voice is still enabled and mid-pass. The intended protocol is safe: disabling a voice takes the per-voice lock the decoder holds, and inputs are freed only after their valid bit is cleared. So this is a title bug that would also corrupt memory on the console. It's not a quick fix, but it is cheap insurance.

Sketch (~18 lines): defer the host dealloc. While the decoder thread exists, heap_free still removes the block and gives the device range back, but pushes (ptr, layout) to a FREED list. The decoder drains that list after each pump(), when no slice is held. The ApuFree tests check device-address ranges, which are still given back immediately.

Upstream: no open PR touches audio.rs.


Generated by Claude Code

**@⁠kekonn** on GitHub · 2026-11-26 12:10 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/230) In `crates/victory-hle/src/modules/audio.rs`, `heap_bytes` (183) returns `&'a mut [u8]` with an unbound lifetime after the `HEAP` guard is dropped. The decoder thread writes output blocks through it (~541-548) and reads input packets (~611-623). `heap_free` (125) removes the block from the map and immediately calls `std::alloc::dealloc`, with no synchronisation against the decoder. **When:** only if the title calls `ApuFree` on a voice's ring or input buffer while the voice is still enabled and mid-pass. The intended protocol is safe: disabling a voice takes the per-voice lock the decoder holds, and inputs are freed only after their valid bit is cleared. So this is a title bug that would also corrupt memory on the console. It's not a quick fix, but it is cheap insurance. **Sketch (~18 lines):** defer the host `dealloc`. While the decoder thread exists, `heap_free` still removes the block and gives the device range back, but pushes `(ptr, layout)` to a `FREED` list. The decoder drains that list after each `pump()`, when no slice is held. The `ApuFree` tests check device-address ranges, which are still given back immediately. **Upstream:** no open PR touches `audio.rs`. --- _Generated by [Claude Code](https://claude.ai/code)_
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:15:59 +00:00
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/avatarmanz--VIctory-7900XTX#230
No description provided.