Formats XMA: reject truncated quant_step escape sequences #3124

Open
Arkenoz wants to merge 1 commit from upstream-pr/3126 into main
Arkenoz commented 2026-11-26 09:15:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Arkenoz on 2026-11-26T09:15:52Z.


Summary

Fixes truncated quant_step escape-code handling in Decoder::subframe (crates/victory-formats/src/xma.rs):

  1. Silent exit on truncated escape: the previous while b.pos + 5 < b.end loop exited silently without signalling an error when the bitstream ended before a terminal 5-bit value (!= 31), allowing truncated subframes (e.g. second subframe with reuse_sf) to decode and return Ok(()).
  2. Corrupted quant_step accumulation: after a premature loop exit, quant_step += if negative { -(quant + step) } else { quant + step } reused the stale step value — adding +32 when step == -32 with 0 iterations (cancelling the initial -32), or double-counting the final 31 after one or more 31 escape codes.
  3. Off-by-one boundary (< vs <=): b.pos + 5 < b.end prevented reading a valid 5-bit escape when exactly 5 bits remained.

The escape loop now reads 5 bits via b.read(5), returns Err(Error("quant step")) on b.overread(), and accumulates quant += esc directly before breaking on esc != 31.

Testing

  • Added three synthetic unit tests in crates/victory-formats/src/xma.rs (all verified failing before the fix and passing after):
    • truncated_negative_quant_step_escape_returns_error
    • truncated_positive_quant_step_escape_after_31_returns_error
    • quant_step_escape_reads_exact_five_remaining_bits
  • rustfmt --edition 2024 --check crates/victory-formats/src/xma.rs — 0 diffs on modified/added lines
  • cargo clippy --workspace --all-targets -- -D warnings — passed
  • cargo check --workspace --all-targets — passed
  • cargo xtask policy — passed (asset policy: 191 files ok)
  • cargo test -p victory-formats --locked — passed (49 passed; 0 failed; 5 ignored)

Coordination & AI disclosure

  • Claimed in #1633.
  • AI-assisted (Antigravity / Gemini 4 Neon).
<!-- greyfinch-sync:Marvisak/VIctory:issue:5507240076 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3126). Originally posted by [Arkenoz](https://github.com/Arkenoz) on 2026-11-26T09:15:52Z. --- ### Summary Fixes truncated `quant_step` escape-code handling in `Decoder::subframe` (`crates/victory-formats/src/xma.rs`): 1. **Silent exit on truncated escape:** the previous `while b.pos + 5 < b.end` loop exited silently without signalling an error when the bitstream ended before a terminal 5-bit value (`!= 31`), allowing truncated subframes (e.g. second subframe with `reuse_sf`) to decode and return `Ok(())`. 2. **Corrupted `quant_step` accumulation:** after a premature loop exit, `quant_step += if negative { -(quant + step) } else { quant + step }` reused the stale `step` value — adding `+32` when `step == -32` with 0 iterations (cancelling the initial `-32`), or double-counting the final `31` after one or more `31` escape codes. 3. **Off-by-one boundary (`<` vs `<=`):** `b.pos + 5 < b.end` prevented reading a valid 5-bit escape when exactly 5 bits remained. The escape loop now reads 5 bits via `b.read(5)`, returns `Err(Error("quant step"))` on `b.overread()`, and accumulates `quant += esc` directly before breaking on `esc != 31`. ### Testing - Added three synthetic unit tests in `crates/victory-formats/src/xma.rs` (all verified failing before the fix and passing after): - `truncated_negative_quant_step_escape_returns_error` - `truncated_positive_quant_step_escape_after_31_returns_error` - `quant_step_escape_reads_exact_five_remaining_bits` - `rustfmt --edition 2024 --check crates/victory-formats/src/xma.rs` — 0 diffs on modified/added lines - `cargo clippy --workspace --all-targets -- -D warnings` — passed - `cargo check --workspace --all-targets` — passed - `cargo xtask policy` — passed (`asset policy: 191 files ok`) - `cargo test -p victory-formats --locked` — passed (`49 passed; 0 failed; 5 ignored`) ### Coordination & AI disclosure - Claimed in #1633. - AI-assisted (Antigravity / Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 10:03:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T10:03:18Z.

Review: APPROVED


Clean fix for all three issues in the quant_step escape loop (xma.rs:1036-1054): checking b.overread() (pos > end) immediately after b.read(5) rejects truncated escape sequences with Error("quant step"), accepts a complete 5-bit terminal code when exactly 5 bits remain, and removes the stale step reuse after loop exit. The two-subframe fixture tests (truncated_negative_quant_step_escape_returns_error, truncated_positive_quant_step_escape_after_31_returns_error, quant_step_escape_reads_exact_five_remaining_bits) exercise the reuse_sf path that previously masked truncation.

Verified locally on Windows 11 x64 (ca16b871):

  • cargo run --locked -p xtask -- policy: passed (191 files ok)
  • cargo clippy -p victory-formats --all-targets --locked -- -D warnings (default and --all-features): clean
  • cargo test -p victory-formats --locked: 49 passed, 0 failed, 5 ignored
  • rustfmt --edition 2024 --check crates/victory-formats/src/xma.rs: 0 diffs in the modified/added hunks (remaining diffs are pre-existing elsewhere in the file)

Optional: adding a valid decode case with repeated 31 escapes followed by a terminal code would also pin down multi-escape accumulation and field alignment end-to-end.

<!-- greyfinch-sync:Marvisak/VIctory:review:6072053221 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3126#pullrequestreview-6072053221). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T10:03:18Z. **Review:** APPROVED --- Clean fix for all three issues in the `quant_step` escape loop (`xma.rs:1036-1054`): checking `b.overread()` (`pos > end`) immediately after `b.read(5)` rejects truncated escape sequences with `Error("quant step")`, accepts a complete 5-bit terminal code when exactly 5 bits remain, and removes the stale `step` reuse after loop exit. The two-subframe fixture tests (`truncated_negative_quant_step_escape_returns_error`, `truncated_positive_quant_step_escape_after_31_returns_error`, `quant_step_escape_reads_exact_five_remaining_bits`) exercise the `reuse_sf` path that previously masked truncation. Verified locally on Windows 11 x64 (`ca16b871`): - `cargo run --locked -p xtask -- policy`: passed (`191 files ok`) - `cargo clippy -p victory-formats --all-targets --locked -- -D warnings` (default and `--all-features`): clean - `cargo test -p victory-formats --locked`: 49 passed, 0 failed, 5 ignored - `rustfmt --edition 2024 --check crates/victory-formats/src/xma.rs`: 0 diffs in the modified/added hunks (remaining diffs are pre-existing elsewhere in the file) Optional: adding a valid decode case with repeated `31` escapes followed by a terminal code would also pin down multi-escape accumulation and field alignment end-to-end.
futurepro62 commented 2026-11-27 11:24:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T11:24:13Z.


NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head ca16b87 (on its base 63bcca4).

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: 869 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: truncated_negative_quant_step_escape_returns_error, truncated_positive_quant_step_escape_after_31_returns_error, quant_step_escape_reads_exact_five_remaining_bits.
  • --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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7217032642 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3126#issuecomment-7217032642). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-27T11:24:13Z. --- NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head `ca16b87` (on its base `63bcca4`). **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`: **869 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `truncated_negative_quant_step_escape_returns_error`, `truncated_positive_quant_step_escape_after_31_returns_error`, `quant_step_escape_reads_exact_five_remaining_bits`. - `--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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3126:upstream-pr/3126'
git switch 'upstream-pr/3126'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3126'
git switch 'upstream-pr/3126'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3126'
git switch 'upstream-pr/3126'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3126'
git switch 'main'
git merge --squash 'upstream-pr/3126'
git switch 'main'
git merge --ff-only 'upstream-pr/3126'
git switch 'main'
git merge 'upstream-pr/3126'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3124
No description provided.