Formats/xma: fix quant_step escape, missing scale factors, empty subframes, and frame truncation #876
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/877"
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 fxceless/victory-fork. Originally posted by adritoyalser on 2026-11-25T11:34:13Z.
Summary
Fixes four bitstream handling bugs in
crates/victory-formats/src/xma.rs(Decoder, disjoint from #627 which only touchesnext_frame):quant_stepescape loop off-by-one and truncation sign inversion (subframe):while b.pos + 5 < b.endskipped a valid 5-bit escape when exactly 5 bits remained (b.pos + 5 == b.end).b.pos + 5 > b.end) with initialstep == -32, the loop did not run andquant_step += -(0 + -32)added+32instead of failing.Err(Error("quantisation step"))whenever fewer than 5 bits remain before a terminating< 31group, and uses saturating arithmetic so corrupted all-1s frames cannot overflowi32.scale_factors):reuse_sf == false) and a subsequent subframe cleared the "new scale factors" bit,scale_factorspreviously succeeded with stale/uninitialized scale factors.Err(Error("missing scale factors"))when!ch.reuse_sfafter the decode branch (matching FFmpeg'swmaprodec.c), checksb.overread(), and uses saturating arithmetic in scale-factor updates and dequantization exponents (exp).tile_header):Err(Error("empty subframe"))) instead of spinning until bitstream overread.bitsargument (decode):bits > data.len() * 8withErr(Error("frame truncated"))while still outputting a silent frame to preserve stream timing.Verification
crates/victory-formats/src/xma.rs:tile_header_rejects_empty_subframe_without_spinningscale_factors_rejects_reuse_without_prior_factors_after_silent_subframequant_step_escape_rejects_truncation_and_reads_exact_taildecode_rejects_bit_length_past_buffer_and_keeps_timingcargo test -q -p victory-formats --lib --locked xma: 9 passed, 0 failed, 2 ignored.cargo clippy -q -p victory-formats --all-targets --locked -- -D warnings: clean (0 warnings).Imported from fxceless/victory-fork. Originally posted by MamaLeVrai on 2026-11-25T12:23:12Z.
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head
290932fintomainf85101bin a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warningsfails with exactly the errorsmainitself has on this machine (placed_filler_twins,depth_written, a sort; PR #841 fixes them), also with--all-features; this PR adds none.cargo test --workspace --locked: run 1: stopped atindirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields(the one that fails onmainitself most runs here (PR #849 and #847 fix its assertion)); run 2: 559 passed, 0 failed, 11 ignored (mainalone: 555 passed, 0 failed, 11 ignored). The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.