Audio capture: guard WASAPI timestamp underflow and stream silence writes #478
No reviewers
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!478
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-478"
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?
@nathanbzrr on GitHub · 2026-11-24 03:50 UTC · original
nathanbzrr:fix/audio-capture-timestamps-and-wav-header→main· +131 −13 · 2 files · 1 commits · openProblem
crates/victory-hle/src/modules/audio/capture.rshad four issues in the diagnostics WAV recorder:header(frames)computedframes * FRAME_BYTES as u64without saturation and only fell back tou32::MAX - 36onu32::try_fromfailure, allowing36 + datato overflow inu32whenframes * 4landed within 36 bytes ofu32::MAX.qpc - *first.get_or_insert(qpc)without checkingAUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR, adjusting the initial timestamp anchor if earlier packets had invalid timestamps, guarding backwards QPC values (checked_sub), or widening intermediateu64math tou128.AUDCLNT_BUFFERFLAGS_SILENTpackets allocated full-gapVec<u8>buffers instead of streaming fixed chunks.std::slice::from_raw_parts(data, bytes)did not guard against nulldatapointers fromGetBuffer.What changed (
f81e3ff)header(frames)withframes.saturating_mul(FRAME_BYTES as u64).min(u64::from(u32::MAX - 36)) as u32so neitherframes * FRAME_BYTESnor36 + datacan overflow.silence_framesto skipAUDCLNT_BUFFERFLAGS_TIMESTAMP_ERRORpackets without anchoringfirst, anchorfirstrelative to already-written frames, guard backwards QPC withchecked_sub, and compute frame positions inu128.write_zerosstreaming[0u8; 16 * 1024]chunks for silence gaps and forAUDCLNT_BUFFERFLAGS_SILENT || data.is_null()packets, keepingwrittenadvancing withsaturating_add.modules::audio::captureunder#[cfg(all(windows, test, not(feature = "diagnostics")))]incrates/victory-hle/src/modules/audio.rs(gating runtime WASAPI items onfeature = "diagnostics") so default-featurecargo test --workspaceexercises the unit tests too.modules::audio::capture::tests:timestamp_errors_and_backwards_qpc_do_not_underflow_or_anchor_zero,write_zeros_streams_exact_byte_count, andheader_clamps_data_and_riff_sizes_without_overflow.Verification (
f81e3ff, Windows MSVC)cargo run -p xtask --locked -- policy&cargo test -p xtask --locked: cleancargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): cleancargo test -p victory-hle --locked audio::capture(default &--all-features): 3 passed, 0 failedNo game files. AI-assisted; reviewed and verified with synthetic unit tests.
8f7df4890ato896677fe00896677fe00tof81e3ff02b@jeremygold02 on GitHub · 2026-11-24 17:35 UTC · original
Verification at
7ac2760d317c62ac05622f5e2edc2c7d1586ff54:cargo test --locked -p victory-hle --features diagnostics --lib capture -- --test-threads=1passed all 3 selected tests:header_caps_riff_size_without_overflow_and_stays_frame_aligned,timestamp_errors_and_backwards_qpc_do_not_underflow_or_anchor_zero, andwrite_zeros_streams_exact_byte_count. This exercises WAV-size clamping/frame alignment, timestamp-error and backwards-QPC handling, long-gap silence accounting, and exact chunked zero writes. It does not exercise live WASAPI capture.This verification was AI-assisted.
@Marvisak on GitHub · 2026-11-25 01:27 UTC · original · edited 2026-11-26 07:20 UTC
Automated triage for the maintainers.
Merge candidate. The new head (
f81e3ff) keeps everything incrates/victory-hle/src/modules/audio/capture.rsthat was checked last time:silence_framesskips timestamp-error packets without anchoring, useschecked_subfor QPC running backwards, and does its math inu128.write_zeroswrites in chunks.headersaturates and clamps data tou32::MAX - 36, so36 + datacan't overflow. The PR body now describes that clamp correctly. Thecfg(all(windows, test, not(feature = "diagnostics")))module lets the three tests run under default features. I checked the test values by hand; they are right.CI: passing.
Generated by Claude Code
@nathanbzrr on GitHub · 2026-11-25 03:14 UTC · original
Addressed the three triage items and rebased onto
origin/main(940d32f, new head8f7df48):bytes > 0 && !data.is_null()check sorecordwrites zeros viawrite_zerosonAUDCLNT_BUFFERFLAGS_SILENT || data.is_null()and always advanceswritten = written.saturating_add(u64::from(frames)).headercap: revertedheader()toorigin/main's implementation (and droppedheader_caps_riff_size_without_overflow_and_stays_frame_aligned), keeping the diff focused on the timestamp underflow guard and chunked zero writes.diagnostics: compiledmodules::audio::captureunder#[cfg(all(windows, test, not(feature = diagnostics)))]incrates/victory-hle/src/modules/audio.rs(keepingpub mod capturegated ondiagnostics) and gated runtime WASAPI items with#[cfg(feature = diagnostics)]so default-featurecargo test --workspaceruns bothcapturetests.Verified on
8f7df48(Windows MSVC):cargo run -p xtask -- policy --staged:asset policy: 2 files okcargo clippy --workspace --all-targets -- -D warnings&--all-features: cleancargo test -p victory-hle --locked capture(default features &--all-features): 2 passed, 0 failedcargo test --workspace --locked: 0 failures across all workspace crates@fuzeofficlal on GitHub · 2026-11-26 01:08 UTC · original
Code review and Windows 11 verification at head
8f7df4890ad0merged cleanly ontomain(63bcca43c6a0):crates/victory-hle/src/modules/audio/capture.rs:134-162, 252,audio.rs:507):silence_framesreturns0onAUDCLNT_BUFFERFLAGS_TIMESTAMP_ERRORwithout anchoringfirst, back-computesfirstwithu128+saturating_sub, guards backwards QPC jumps viachecked_sub, and converts timestamps to frames inu128without overflow.write_zerosstreams from a fixed 16 KiB static zero buffer instead of allocating a potentially hugeVec, andrecord()routesAUDCLNT_BUFFERFLAGS_SILENT || data.is_null()safely throughwrite_zeros. Default vs--features diagnosticscfg gating compiles cleanly with 0 warnings.cargo xtask policy:191 files ok;cargo clippy --locked -p victory-hle --tests -- -D warnings(default +--features diagnostics): 0 warningsvictory-hle -- audio: 10/10 passed on both default and--features diagnostics(including both new regression tests).LGTM.
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.