Formats: XMA bit reads of 0 or more than 32 bits do not overflow a shift #992
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/992"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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) andBits::signed(n)/Bits::read(n)for n > 32 underflowed32 - 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
signedis 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.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T15:15:56Z.
Review: APPROVED
Tested
87f7cb89on Windows 11, RTX 5070, MSVC:cargo test -p victory-formats24 passed, includingbits_read_zero_full_and_oversized_widths.cargo clippy -p victory-formats --all-targets -- -D warningsis clean.signed(0)(shift by 32) andread/signedpast 32 bits (32 - nunderflow) are now defined: 0 for no bits, the low 32 bits for wide fields, with allnbits 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).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T15:41:42Z.
Review: APPROVED
Bits::read/signedno longer overflow a shift at the width edges:n == 0returns 0 (the oldsigned(0)shifted by 32 — a debug panic),n == 32takes the word path, andn > 32consumes allnbits 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.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-formatspasses, 24 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
Pull request closed