Formats: XMA bit reads of 0 or more than 32 bits do not overflow a shift #992

Closed
NATON4 wants to merge 1 commit from upstream-pr/992 into main
NATON4 commented 2026-11-24 14:44:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by NATON4 on 2026-11-24T14:44:38Z.


Bits::signed(0) shifted by 32 (a panic in debug builds) and Bits::signed(n) / Bits::read(n) for n > 32 underflowed 32 - n. Zero bits now read as 0; past 32 bits the low 32 are the value and all n bits are consumed, for both. Widths 1 to 32 read as before.

No caller reaches these widths today (the decoder clamps to two channels, so the widest read is 16 bits and signed is only called with 6); this keeps a later caller or a damaged stream from panicking the decoder. The new test panics on the old code and passes now.

Closes #907.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6584400833 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/992). Originally posted by [NATON4](https://github.com/NATON4) on 2026-11-24T14:44:38Z. --- `Bits::signed(0)` shifted by 32 (a panic in debug builds) and `Bits::signed(n)` / `Bits::read(n)` for n > 32 underflowed `32 - n`. Zero bits now read as 0; past 32 bits the low 32 are the value and all n bits are consumed, for both. Widths 1 to 32 read as before. No caller reaches these widths today (the decoder clamps to two channels, so the widest read is 16 bits and `signed` is only called with 6); this keeps a later caller or a damaged stream from panicking the decoder. The new test panics on the old code and passes now. Closes #907.
mercuryVM commented 2026-11-24 16:04:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T15:15:56Z.

Review: APPROVED


Tested 87f7cb89 on Windows 11, RTX 5070, MSVC: cargo test -p victory-formats 24 passed, including bits_read_zero_full_and_oversized_widths. cargo clippy -p victory-formats --all-targets -- -D warnings is clean.

  • signed(0) (shift by 32) and read/signed past 32 bits (32 - n underflow) are now defined: 0 for no bits, the low 32 bits for wide fields, with all n bits consumed. Widths 1 to 32 keep their old expression, so current callers, which top out at 16 bits as you note, are unaffected.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6041971887 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/992#pullrequestreview-6041971887). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T15:15:56Z. **Review:** APPROVED --- Tested 87f7cb89 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-formats` 24 passed, including `bits_read_zero_full_and_oversized_widths`. `cargo clippy -p victory-formats --all-targets -- -D warnings` is clean. - `signed(0)` (shift by 32) and `read`/`signed` past 32 bits (`32 - n` underflow) are now defined: 0 for no bits, the low 32 bits for wide fields, with all `n` bits consumed. Widths 1 to 32 keep their old expression, so current callers, which top out at 16 bits as you note, are unaffected. AI-assisted (Claude Code).
catminou4 commented 2026-11-24 16:04:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T15:41:42Z.

Review: APPROVED


Bits::read/signed no longer overflow a shift at the width edges: n == 0 returns 0 (the old signed(0) shifted by 32 — a debug panic), n == 32 takes the word path, and n > 32 consumes all n bits while keeping the low 32, which is the documented contract. The new test pins exactly these edges (zero/full/40-bit widths, consumption accounting, and the sign-extension boundary at 32). Small, precise, and it removes a real panic path on malformed XMA packets.

Verified locally: test-merge with main (ffe310e) clean; cargo test -p victory-formats --locked (macOS arm64, rustc 1.98.1) → 24 passed / 0 failed / 4 ignored (the ignored ones are the usual platform-gated cases). Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6042460811 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/992#pullrequestreview-6042460811). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T15:41:42Z. **Review:** APPROVED --- `Bits::read`/`signed` no longer overflow a shift at the width edges: `n == 0` returns 0 (the old `signed(0)` shifted by 32 — a debug panic), `n == 32` takes the word path, and `n > 32` consumes all `n` bits while keeping the low 32, which is the documented contract. The new test pins exactly these edges (zero/full/40-bit widths, consumption accounting, and the sign-extension boundary at 32). Small, precise, and it removes a real panic path on malformed XMA packets. Verified locally: test-merge with main (`ffe310e`) clean; `cargo test -p victory-formats --locked` (macOS arm64, rustc 1.98.1) → **24 passed / 0 failed / 4 ignored** (the ignored ones are the usual platform-gated cases). Approving.
Zipettte commented 2026-11-24 16:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:13:01Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 87f7cb8: cargo test -p victory-formats passes, 24 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7135650265 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/992#issuecomment-7135650265). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T15:13:01Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 87f7cb8: `cargo test -p victory-formats` passes, 24 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
upstream-sync closed this pull request 2026-11-24 20:01:42 +00:00

Pull request closed

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!992
No description provided.