Repository navigation
Audio capture: guard WASAPI timestamp underflow and stream silence writes - #478
nathanbzrr wants to merge 1 commit into
Conversation
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 7ac2760 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed). These are diagnostics-only code paths, and I have not run a live capture.
header:MAX_DATA_BYTES = (u32::MAX - 36) & !3keeps36 + datafrom overflowing, and the data length stays a whole number of frames. The test's 4294967256 matches.silence_frames:- Packets flagged
TIMESTAMP_ERRORneither anchor nor pad. - The anchor is
qpcminus the time already written, so a late first good timestamp does not insert a burst of silence for frames already written. - A backwards QPC (
checked_sub) pads nothing instead of underflowing.
- Packets flagged
- Streaming
write_zerosremoves the unboundedvec![0; gap], which a long gap could make huge. - A non-silent packet with a null
datanow writes nothing and does not advancewritten. The next packet's silence check then makes up the gap, which is a reasonable outcome.
No issues found.
AI-assisted (Claude Code).
… errors/underflow, null 0-frame slice UB, unbounded silence allocation, and WAV header u32 overflow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verification at
This verification was AI-assisted. |
…rflow, null 0-frame slice UB, unbounded silence allocation, and WAV header u32 overflow
…rflow, null 0-frame slice UB, unbounded silence allocation, and WAV header u32 overflow
…rflow, null 0-frame slice UB, unbounded silence allocation, and WAV header u32 overflow
|
Automated triage for the maintainers. Merge candidate. The new head (
CI: passing. Generated by Claude Code |
7ac2760 to
8f7df48
Compare
|
Addressed the three triage items and rebased onto
Verified on
|
…nd stream silence writes
…nd stream silence writes
|
Code review and Windows 11 verification at head
LGTM. |
8f7df48 to
896677f
Compare
…nd stream silence writes
…es, and stream silence writes
896677f to
f81e3ff
Compare
Problem
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.