HLE audio capture: fix WAV/QPC overflows, chunk silence writes, close target handle #1309

Closed
geiyiliyabumo wants to merge 1 commit from upstream-pr/1309 into main
geiyiliyabumo commented 2026-11-24 17:18:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T17:18:28Z.


Summary

Audits \crates/victory-hle/src/modules/audio/capture.rs\ (previously 0 tests) and fixes five bugs:

  • Clamps \header(frames)\ data length at \u32::MAX - 36\ with saturating \u64\ multiplication so \36 + data\ can never overflow \u32\ when \ rames * 4\ is near \u32::MAX.
  • Handles retrograde QPC timestamps, \AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR, and large \delta * RATE\ values via \saturating_sub\ and \u128\ math instead of panicking/underflowing.
  • Streams silence gaps and silent packets from a fixed 4 KiB stack buffer instead of allocating a single unbounded \Vec\ for long silence stretches.
  • Avoids \slice::from_raw_parts\ UB when \ rames == 0\ or \data.is_null(), wraps the opened target process handle in an RAII \CloseHandle\ guard, exits activation polling if the target exits early, and ignores empty \VICTORY_AUDIO_CAPTURE="".
  • Adds 6 deterministic synthetic unit tests under --features diagnostics.

Verification

  • \cargo test -p victory-hle --features diagnostics --lib modules::audio::capture\ ? 6 passed, 0 failed
  • \cargo clippy -p victory-hle --all-targets --features diagnostics -- -D warnings\ ? clean
  • \cargo xtask policy\ ? 154 files ok

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587433744 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1309). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T17:18:28Z. --- ## Summary Audits \crates/victory-hle/src/modules/audio/capture.rs\ (previously 0 tests) and fixes five bugs: - Clamps \header(frames)\ data length at \u32::MAX - 36\ with saturating \u64\ multiplication so \36 + data\ can never overflow \u32\ when \ rames * 4\ is near \u32::MAX\. - Handles retrograde QPC timestamps, \AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR\, and large \delta * RATE\ values via \saturating_sub\ and \u128\ math instead of panicking/underflowing. - Streams silence gaps and silent packets from a fixed 4 KiB stack buffer instead of allocating a single unbounded \Vec\ for long silence stretches. - Avoids \slice::from_raw_parts\ UB when \ rames == 0\ or \data.is_null()\, wraps the opened target process handle in an RAII \CloseHandle\ guard, exits activation polling if the target exits early, and ignores empty \VICTORY_AUDIO_CAPTURE=""\. - Adds 6 deterministic synthetic unit tests under \--features diagnostics\. ## Verification - \cargo test -p victory-hle --features diagnostics --lib modules::audio::capture\ ? 6 passed, 0 failed - \cargo clippy -p victory-hle --all-targets --features diagnostics -- -D warnings\ ? clean - \cargo xtask policy\ ? 154 files ok *AI-assisted; synthetic tests only, no game files.*
DenRakEiw commented 2026-11-24 18:04:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T17:26:43Z.

Review: APPROVED


Tested merged cleanly onto main (ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-hle: 94 passed, 0 failed (plus no_dll_planting: 1 passed)
  • cargo clippy -p victory-hle --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean overflow/chunking/handle-close fixes in audio capture. Approving.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6044159484 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1309#pullrequestreview-6044159484). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T17:26:43Z. **Review:** APPROVED --- Tested merged cleanly onto `main` (`ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC): - `cargo test -p victory-hle`: **94 passed, 0 failed** (plus `no_dll_planting`: 1 passed) - `cargo clippy -p victory-hle --all-targets`: **0 warnings** - `cargo xtask policy`: ok Clean overflow/chunking/handle-close fixes in audio capture. Approving. AI-assisted (Gemini 4 Neon).
muhammed-aksoy commented 2026-11-24 18:06:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by muhammed-aksoy on 2026-11-24T17:54:18Z.


I tested 0e8c0eb on Windows against ffe310e. The HLE package passed 95 tests. In a local batch with #1279, #1283, #1307, and #1311, the all-features Windows workspace suite passed 360 tests with six ignored and zero failures. Clippy with warnings denied and asset policy passed at batch commit 1409f9c. WARP was selected for the GPU tests. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139872856 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1309#issuecomment-7139872856). Originally posted by [muhammed-aksoy](https://github.com/muhammed-aksoy) on 2026-11-24T17:54:18Z. --- I tested `0e8c0eb` on Windows against `ffe310e`. The HLE package passed 95 tests. In a local batch with #1279, #1283, #1307, and #1311, the all-features Windows workspace suite passed 360 tests with six ignored and zero failures. Clippy with warnings denied and asset policy passed at batch commit `1409f9c`. WARP was selected for the GPU tests. AI-assisted.
upstream-sync closed this pull request 2026-11-25 01:06:12 +00:00
Marvisak commented 2026-11-25 01:08:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:37:13Z.


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #478. The same four capture.rs hardenings as the earlier and smaller #478, plus a process-handle guard and an empty-variable check of no practical effect (the recorder process exits when done).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148702224 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1309#issuecomment-7148702224). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:37:13Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #478. The same four capture.rs hardenings as the earlier and smaller #478, plus a process-handle guard and an empty-variable check of no practical effect (the recorder process exits when done). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1309
No description provided.