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. In On your reply: all three points are addressed as described, checked on head Generated by Claude Code |
7ac2760 to
8f7df48
Compare
|
Addressed the three triage items and rebased onto
Verified on
|
…nd stream silence writes
Problem
crates/victory-hle/src/modules/audio/capture.rshad four robustness issues in the diagnostics WAV recorder:header(frames)multipliedframes * FRAME_BYTESwithout saturating arithmetic, could overflow36 + datainu32for frame counts just below 4 GiB, and used an unaligned fallback (u32::MAX - 36) that violated 4-bytenBlockAlign.qpc - *first.get_or_insert(qpc)without checkingAUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR, adjusting the initial timestamp anchor if earlier packets had invalid timestamps, guarding against 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 zero-byte or nulldatapointers fromGetBuffer.What changed
headerdata byte counts withsaturating_muland 4-byte-alignedMAX_DATA_BYTES = (u32::MAX - 36) & !(FRAME_BYTES as u32 - 1).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 both silence gaps andAUDCLNT_BUFFERFLAGS_SILENTpackets.std::slice::from_raw_partswithbytes > 0 && !data.is_null()andusize::try_from(bytes).modules::audio::capture::tests.Tests (isolated branch
7ac2760)rustfmt --edition 2024 --check crates/victory-hle/src/modules/audio/capture.rs: 0 diffs in all modified/added lines (only pre-existing lines 15-26WAIT_OBJECT_0import ordering left untouched to avoid conflicting with Build: Linux workspace, contributor setup and CI #112).cargo test -p victory-hle --features diagnostics --lib audio::capture: 3 passed, 0 failed, 86 filtered out (modules::audio::capture::tests::header_caps_riff_size_without_overflow_and_stays_frame_aligned,modules::audio::capture::tests::timestamp_errors_and_backwards_qpc_do_not_underflow_or_anchor_zero,modules::audio::capture::tests::write_zeros_streams_exact_byte_count).cargo test -p victory-hle --lib: 86 passed, 0 failed.cargo clippy -p victory-hle --all-targets --all-features: passed (exit 0; 0 errors/warnings incapture.rs).cargo xtask policy:asset policy: 151 files ok.No game files. AI-assisted; reviewed and verified with the tests above.