formats: guard bitstream signed and 32-bit shift overflows in xma #1154
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1154"
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 DaniiL35 on 2026-11-24T16:16:54Z.
Resolves #907
Problem
In
crates/victory-formats/src/xma.rs:Bits::signed(n)computedlet sign = 1u32 << (n - 1);without checking ifn == 0(underflow ton - 1 == u32::MAX, causing1u32 << 4294967295overflow panic) orn > 32. Furthermore,val - (1 << n)overflows ifn == 32andvalis non-negative.Bits::read(n)evaluatedlet mask = (1u32 << n) - 1;without checking forn >= 32. Whenn == 32, Rust panics in debug builds on1u32 << 32.Fix
n == 0explicitly inBits::signedreturning0.n >= 32with sign-extension logic (val as i32) and clamp1u64 << nwithout shift overflow.Bits::read, handlen == 0(mask0) andn >= 32(masku32::MAX).bitstream_handles_zero_and_boundary_bit_widthsverifying zero width, 1-bit, 31-bit, 32-bit, and signed conversions.All fixtures are synthetic; zero game data (Rule #1 compliant). Formatted with Rust 2024 edition.
Pull request closed