Skip to content

audren: validate command lists before capture diagnostics - #802

Closed
thehobbit85 wants to merge 2 commits into
seedds:mainfrom
thehobbit85:codex/audren-capture-validation
Closed

thehobbit85 wants to merge 2 commits into
seedds:mainfrom
thehobbit85:codex/audren-capture-validation

Conversation

@thehobbit85

@thehobbit85 thehobbit85 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What and why

A short valid audio command list can select the SDK layout before the first full list arrives. If that next list is malformed, capture used to log an uninitialized histogram string or consume sink discovery from a valid prefix. A long histogram also advanced its next append past the buffer after snprintf truncated an entry.

Validate every command before histogram discovery or PCM output. Initialize the histogram string and stop at the last complete entry that fits. Malformed lists leave discovery pending for the next valid list. The existing native layout test now covers first/middle/trailing malformed commands, stereo recovery across SDK 4/5/6/16/21, and 64,000 synthetic commands whose histogram exceeds the buffer.

Related to #313 (comment). This addresses only the audio finding; the roadmap remains open. Checked current diffs of overlapping PRs #160, #193, #231 and #444, plus the earlier startup-layout fix #331: none resolves these paths.

Initial validation on 898145e5

  • Reproduced both defects before the fix under native arm64 ASan: a 513-byte read beyond the histogram string and an out-of-bounds write after truncation. The new plain test also failed before production changes.
  • Focused layout test passes plain and unsuppressed ASan/UBSan with pattern-initialized stack locals.
  • Full host unit suite, full host ASan/UBSan ratchet, host tsan-threads, and native Mac host build pass (GAME=010015100B514000).
  • Full native graphics suite passes; six unavailable game-derived reflection samples are skipped.
  • All 111 Python test files pass (990 cases including 23 optional skips). Python lint: 392 baseline findings, zero new or stale fixed findings. Documentation tests and generated symptom index pass.
  • C compile database generated for 205 sources. LLVM 23 clang-tidy is absent, so C lint could not run. No tools were installed.
  • Game regression could not run: no game files or configured harness root/games directory. Selected Super Mario Bros. Wonder, Mario Kart 8 Deluxe, Bastion, Fire Emblem: Three Houses and Rhythm Heaven Groove to cover SDK 16/4/5/6/21. No gameplay or listening claim.
  • Impact identifies Breath of the Wild, Pokemon Scarlet and Tears of the Kingdom as affected, Hades as unaffected, and 116 profiles with unknown coverage. These also remain unchecked without game files.

Docs

The mechanism and synthetic reproductions are in docs/reference/audio.md; the symptom index is regenerated. No game files, keys, or extracted game data are included.

CI follow-up and main integration

Rebased onto main 5474c6f3 and replaced the two new test-only rewind calls with checked fseek calls, addressing CI's bugprone-unsafe-functions findings without changing its lint baseline. Published head: 3b389417. Full host suite, focused audio capture tests, pattern-initialized ASan/UBSan and documentation tests pass on this head. LLVM 23 remains unavailable locally, so the new CI run must confirm clang-tidy.

Validate the complete command list before histogram discovery or PCM output, and stop histogram appends before their snprintf return value can leave the buffer. Cover malformed later lists, stereo recovery across supported layouts, and oversized histograms with native regression cases.

Related to seedds#313 (comment)
@thehobbit85
thehobbit85 force-pushed the codex/audren-capture-validation branch from 898145e to 3b38941 Compare October 31, 2026 22:09
seedds added a commit that referenced this pull request Nov 1, 2026
Validate the complete command list before histogram discovery or PCM
output. Initialize the histogram and stop appends before snprintf's
untruncated length can advance beyond the buffer.

The regression fixture covers malformed-list rejection and stereo
recovery across SDK 4/5/6/16/21, plus oversized histogram formatting.
The previous code reproduces both bounds violations under ASan/UBSan;
the fixed fixture passes plain and sanitized with patterned stack locals.

Co-authored-by: Eliran Zach <[email protected]>
@seedds

seedds commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Landed on main as b8ffaf8, keeping this as its own small fix. @thehobbit85 is credited as co-author because the implementation and regression coverage were retained.

Design and correctness review found no blockers: complete structural validation precedes discovery and PCM output, and histogram formatting respects snprintf's return contract. This is a general root-cause fix with no game-specific rule or workaround.

Independently reproduced both original bounds violations under ASan/UBSan. The fixed layout fixture passes plain and unsuppressed ASan/UBSan with patterned stack locals, including malformed-list rejection, recovery across SDK 4/5/6/16/21, and the oversized histogram. The combined landing also passes the focused filesystem/save-sync fixtures and all 11 documentation checks. Published PR CI was green.

Confidence is high. Regression risk is low because valid-list PCM behavior is preserved; no gameplay regression or listening pass was run. Closing as landed.

@seedds seedds closed this Nov 1, 2026
@thehobbit85
thehobbit85 deleted the codex/audren-capture-validation branch November 1, 2026 04:42
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Validate the complete command list before histogram discovery or PCM
output. Initialize the histogram and stop appends before snprintf's
untruncated length can advance beyond the buffer.

The regression fixture covers malformed-list rejection and stereo
recovery across SDK 4/5/6/16/21, plus oversized histogram formatting.
The previous code reproduces both bounds violations under ASan/UBSan;
the fixed fixture passes plain and sanitized with patterned stack locals.

Co-authored-by: Eliran Zach <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants