Find the first XMA frame when a buffer starts with continuation data #2708

Open
github-bot wants to merge 2 commits from github-bot/gh-2708 into main AGit
Owner

@⁠VlREX on GitHub · 2026-11-25 18:33 UTC · original
VlREX:fix/xma-stream-walk → main · +46 −9 · 2 files · 2 commits · open

The audio context assumed packet zero announced a frame on initial input and on buffer switches. Follow the stream skip counts past packets with no frame starts, and check the announced offset is in its packet and buffer. Explicit playback positions still use the supplied offset. This changes initial frame selection; #2694 covers advancing from an already decoded frame. Two synthetic regression tests failed with the old selection logic. Windows GNU victory-formats tests: 40 passed, 5 ignored. No game data used.

**@⁠VlREX** on GitHub · 2026-11-25 18:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2708) `VlREX:fix/xma-stream-walk` → `main` · +46 −9 · 2 files · 2 commits · open The audio context assumed packet zero announced a frame on initial input and on buffer switches. Follow the stream skip counts past packets with no frame starts, and check the announced offset is in its packet and buffer. Explicit playback positions still use the supplied offset. This changes initial frame selection; #2694 covers advancing from an already decoded frame. Two synthetic regression tests failed with the old selection logic. Windows GNU victory-formats tests: 40 passed, 5 ignored. No game data used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:30 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 18:50 UTC · original

Right split with #2694: this fixes initial selection (packet zero need not announce a frame - continuation data is legal), #2694 fixes advancing. Walking the stream skip chain until a packet with frames != 0 and then bounds-checking the announced offset inside both packet and buffer covers both failure shapes. Nice that the existing decode tests got switched to first_frame so they pin it end-to-end.

**@⁠kotekompotek** on GitHub · 2026-11-25 18:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2708#issuecomment-7171483273) Right split with #2694: this fixes initial selection (packet zero need not announce a frame - continuation data is legal), #2694 fixes advancing. Walking the stream skip chain until a packet with frames != 0 and then bounds-checking the announced offset inside both packet and buffer covers both failure shapes. Nice that the existing decode tests got switched to first_frame so they pin it end-to-end.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 18:54 UTC · original

Independent WARP/CPU verification

PR head: 09a519b9a5120380019adff3537cd56e0feb6fc4
Environment: Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1, WARP only (VICTORY_WARP=1 + VICTORY_D3D12_WARP=1), dxil.dll 1.8.2502.11 (Windows SDK 10.0.26100.0), no physical GPU touched, no game files/dumps/retail hashes. CARGO_TARGET_DIR on D:, --locked throughout. origin/main = 13f91caee25f2fdf2c062be5f7a27f058e51cbca; merges cleanly (git merge-tree); open, non-draft, no oni-swr comment on this head.

Commands / results (cargo test --locked -p victory-formats -p victory-hle):

  • Baseline: victory-formats 38 passed / 0 failed / 5 ignored; victory-hle 146 passed (after one flaky rerun, see below).
  • PR: victory-formats 40 passed / 0 failed / 5 ignored; victory-hle 146 passed / 0 failed. Doctests pass.
  • cargo clippy --locked -p victory-formats -p victory-hle --all-targets -- -D warnings → clean.
  • Negative control: making first_frame stop at packet 0 (index += ... → return None) makes first_frame_follows_stream_skips_past_continuation_packets FAIL.
    Baseline note: on the very first baseline victory-hle run, dstorage::tests::a_page_list_filled_after_its_request_starts failed once (assertion left==right); it passed 3/3 reruns in isolation and in a full rerun (146/146), so it looks like a flaky pre-existing test unrelated to this PR.

Review: logic is correct: skips packets with frames == 0 following the stream skip count, bounds-checks the first-frame offset against the packet and the data length, and uses checked_mul/add. The loop terminates because packet returns None past the data. Both new tests cover a continuation-packet case and the out-of-payload offset. Nit (non-blocking): the new first_frame tests were inserted between the doc comment of noise_packets_walk_and_decode and that test, so that doc comment is now attached to the wrong test. The debug log now reports frame.start instead of at, which is more accurate.

Not tested: physical hardware GPU, retail game run, release build.
AI use: Claude Code (Claude Sonnet 5.5). Claim: #1633

**@⁠oni-swr** on GitHub · 2026-11-25 18:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2708#issuecomment-7171558312) ## Independent WARP/CPU verification **PR head:** `09a519b9a5120380019adff3537cd56e0feb6fc4` **Environment:** Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1, WARP only (`VICTORY_WARP=1` + `VICTORY_D3D12_WARP=1`), `dxil.dll` 1.8.2502.11 (Windows SDK 10.0.26100.0), no physical GPU touched, no game files/dumps/retail hashes. `CARGO_TARGET_DIR` on D:, `--locked` throughout. `origin/main` = `13f91caee25f2fdf2c062be5f7a27f058e51cbca`; merges cleanly (`git merge-tree`); open, non-draft, no `oni-swr` comment on this head. **Commands / results** (`cargo test --locked -p victory-formats -p victory-hle`): - Baseline: victory-formats 38 passed / 0 failed / 5 ignored; victory-hle 146 passed (after one flaky rerun, see below). - PR: victory-formats **40 passed** / 0 failed / 5 ignored; victory-hle 146 passed / 0 failed. Doctests pass. - `cargo clippy --locked -p victory-formats -p victory-hle --all-targets -- -D warnings` → clean. - **Negative control:** making `first_frame` stop at packet 0 (`index += ...` → `return None`) makes `first_frame_follows_stream_skips_past_continuation_packets` FAIL. Baseline note: on the very first baseline `victory-hle` run, `dstorage::tests::a_page_list_filled_after_its_request_starts` failed once (assertion left==right); it passed 3/3 reruns in isolation and in a full rerun (146/146), so it looks like a flaky pre-existing test unrelated to this PR. **Review:** logic is correct: skips packets with `frames == 0` following the stream skip count, bounds-checks the first-frame offset against the packet and the data length, and uses `checked_mul/add`. The loop terminates because `packet` returns `None` past the data. Both new tests cover a continuation-packet case and the out-of-payload offset. Nit (non-blocking): the new `first_frame` tests were inserted between the doc comment of `noise_packets_walk_and_decode` and that test, so that doc comment is now attached to the wrong test. The debug log now reports `frame.start` instead of `at`, which is more accurate. **Not tested:** physical hardware GPU, retail game run, release build. **AI use:** Claude Code (Claude Sonnet 5.5). Claim: https://git.gtahub.st/github/Marvisak--VIctory/issues/1633
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 18:54 UTC · original

Independent Windows 11 verification and boundary review of 09a519b9 (on 13f91ca):

Verification (rustc 1.98.1 MSVC)

  • cargo clippy --locked -p victory-formats -p victory-hle --all-targets -- -D warnings: 0 warnings.
  • cargo test --locked -p victory-formats: 40 passed, 0 failed, 5 ignored (both new first_frame tests pass).
  • cargo test --locked -p victory-hle: 146 passed, 0 failed (lib), plus fidelityfx and no_dll_planting checks clean.
  • Merge compatibility with #2694: clean zero-conflict 3-way git merge-tree with #2694 (1cd96506); the two PRs touch disjoint paths (first_frame initial/buffer-switch lookup vs next_frame stepping) and complement each other cleanly.

Review Notes

  • first_frame safely advances past leading continuation packets (frames == 0) via strictly increasing index += 1 + header.skip as usize, bounds packet reads via packet(data, index)?, rejects out-of-packet offset >= PACKET_BITS, uses checked arithmetic for bit offsets, and verifies start / 8 < data.len() — safe on empty, truncated, all-zero, or malformed buffers.
  • Keeping if at < 32 { xma::first_frame(data) } else { Some(at) } preserves explicit loop/resume offsets (at >= 32) while fixing buffer-start continuation streams.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 18:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2708#issuecomment-7171559309) Independent Windows 11 verification and boundary review of `09a519b9` (on `13f91ca`): ### Verification (`rustc 1.98.1` MSVC) - `cargo clippy --locked -p victory-formats -p victory-hle --all-targets -- -D warnings`: **0 warnings**. - `cargo test --locked -p victory-formats`: **40 passed, 0 failed, 5 ignored** (both new `first_frame` tests pass). - `cargo test --locked -p victory-hle`: **146 passed, 0 failed** (`lib`), plus `fidelityfx` and `no_dll_planting` checks clean. - **Merge compatibility with #2694:** clean zero-conflict 3-way `git merge-tree` with #2694 (`1cd96506`); the two PRs touch disjoint paths (`first_frame` initial/buffer-switch lookup vs `next_frame` stepping) and complement each other cleanly. ### Review Notes - `first_frame` safely advances past leading continuation packets (`frames == 0`) via strictly increasing `index += 1 + header.skip as usize`, bounds packet reads via `packet(data, index)?`, rejects out-of-packet `offset >= PACKET_BITS`, uses checked arithmetic for bit offsets, and verifies `start / 8 < data.len()` — safe on empty, truncated, all-zero, or malformed buffers. - Keeping `if at < 32 { xma::first_frame(data) } else { Some(at) }` preserves explicit loop/resume offsets (`at >= 32`) while fixing buffer-start continuation streams.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:22 UTC · original

Automated triage for the maintainers.

Merge candidate (recommend a look). When an XMA context starts at the beginning of its input buffer, decode in crates/victory-hle/src/modules/audio.rs used packet 0's first-frame offset even when packet 0 announced no frame (continuation data), so it read from a meaningless position. The new xma::first_frame (crates/victory-formats/src/xma.rs) follows the stream's packet-skip counts to the first packet that announces a frame, the same walk next_frame already does, and bounds-checks the offset against the packet and the buffer with checked arithmetic. It terminates because packet returns None past the data. Explicit read positions (at >= 32) are unchanged, and the existing decode tests now start through first_frame. It is complementary to #2694 and merges cleanly with it and with #2709/#2710/#2714.

Nit: the two new tests were inserted between noise_packets_walk_and_decode and its doc comment, so that comment now sits on first_frame_follows_stream_skips_past_continuation_packets.

CI: check passing on this head.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2708#issuecomment-7176276532) <!-- victory-triage v1 head=09a519b9a5120380019adff3537cd56e0feb6fc4 verdict=merge-candidate at=2026-11-25T22:23:00Z --> Automated triage for the maintainers. **Merge candidate (recommend a look).** When an XMA context starts at the beginning of its input buffer, `decode` in `crates/victory-hle/src/modules/audio.rs` used packet 0's first-frame offset even when packet 0 announced no frame (continuation data), so it read from a meaningless position. The new `xma::first_frame` (`crates/victory-formats/src/xma.rs`) follows the stream's packet-skip counts to the first packet that announces a frame, the same walk `next_frame` already does, and bounds-checks the offset against the packet and the buffer with checked arithmetic. It terminates because `packet` returns `None` past the data. Explicit read positions (`at >= 32`) are unchanged, and the existing decode tests now start through `first_frame`. It is complementary to #2694 and merges cleanly with it and with #2709/#2710/#2714. Nit: the two new tests were inserted between `noise_packets_walk_and_decode` and its doc comment, so that comment now sits on `first_frame_follows_stream_skips_past_continuation_packets`. CI: `check` passing on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 05:18 UTC · original · approved these changes

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:

  • Diff review: xma::first_frame walks packet headers following 1 + header.skip until a packet announces frames (header.frames != 0), bounds-checks HEADER_BITS + header.first_frame_bit < PACKET_BITS and start / 8 < data.len() with checked arithmetic, and avoids reading into continuation packets or out-of-payload offsets when audio::decode starts a fresh buffer.
  • cargo test -p victory-formats xma: 22 passed, 0 failed (including first_frame_follows_stream_skips_past_continuation_packets and first_frame_rejects_an_offset_outside_the_announcing_payload).
  • cargo test -p victory-hle audio: 8 passed, 0 failed.
  • cargo clippy -p victory-formats -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 05:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2708#pullrequestreview-6068920107) · **approved these changes** Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - Diff review: `xma::first_frame` walks packet headers following `1 + header.skip` until a packet announces frames (`header.frames != 0`), bounds-checks `HEADER_BITS + header.first_frame_bit < PACKET_BITS` and `start / 8 < data.len()` with checked arithmetic, and avoids reading into continuation packets or out-of-payload offsets when `audio::decode` starts a fresh buffer. - `cargo test -p victory-formats xma`: 22 passed, 0 failed (including `first_frame_follows_stream_skips_past_continuation_packets` and `first_frame_rejects_an_offset_outside_the_announcing_payload`). - `cargo test -p victory-hle audio`: 8 passed, 0 failed. - `cargo clippy -p victory-formats -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 11:55 UTC · original

NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head 09a519b (on its base 13f91ca).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 775 passed, 0 failed, 9 ignored.
  • The new tests ran and passed: first_frame_follows_stream_skips_past_continuation_packets, first_frame_rejects_an_offset_outside_the_announcing_payload.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 11:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2708#issuecomment-7191340992) NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head `09a519b` (on its base `13f91ca`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **775 passed, 0 failed, 9 ignored**. - The new tests ran and passed: `first_frame_follows_stream_skips_past_continuation_packets`, `first_frame_rejects_an_offset_outside_the_announcing_payload`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2708/head:github-bot/gh-2708'
git switch 'github-bot/gh-2708'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2708'
git switch 'github-bot/gh-2708'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2708'
git switch 'github-bot/gh-2708'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2708'
git switch 'main'
git merge --squash 'github-bot/gh-2708'
git switch 'main'
git merge --ff-only 'github-bot/gh-2708'
git switch 'main'
git merge 'github-bot/gh-2708'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2708
No description provided.