Formats XMA: reject truncated quant_step escape sequences #3126

Open
github-bot wants to merge 1 commit from github-bot/gh-3126 into main AGit
Owner

@⁠Arkenoz on GitHub · 2026-11-26 09:15 UTC · original
Arkenoz:fix/xma-quant-step-escape → main · +119 −6 · 1 files · 1 commits · open

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).
**@⁠Arkenoz** on GitHub · 2026-11-26 09:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/3126) `Arkenoz:fix/xma-quant-step-escape` → `main` · +119 −6 · 1 files · 1 commits · open ### 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:04 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 10:03 UTC · original · approved these changes

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 10:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3126#pullrequestreview-6072053221) · **approved these changes** 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.
This pull request can be merged automatically.
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/3126/head:github-bot/gh-3126'
git switch 'github-bot/gh-3126'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3126'
git switch 'github-bot/gh-3126'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3126'
git switch 'github-bot/gh-3126'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3126'
git switch 'main'
git merge --squash 'github-bot/gh-3126'
git switch 'main'
git merge --ff-only 'github-bot/gh-3126'
git switch 'main'
git merge 'github-bot/gh-3126'
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!3126
No description provided.