formats/bcpack: validate BC7 ctrl7 entries in Tables::parse #790
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!790
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-790"
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?
@AscilCH on GitHub · 2026-11-25 07:35 UTC · original
AscilCH:fix/formats-bcpack-ctrl7-mode-rot-validation→main· +60 −0 · 1 files · 1 commits · openSummary
Validate BC7
ctrl7table entries inTables::parse()(crates/victory-formats/src/bcpack.rs):Tables::parse()previously loaded all 512ctrl7u16entries without checking their(mode, subsets, rot, part)fields.mode in {0, 1, 3}androt == 1causedbc7_precision()to swapprec[3] == 0intoprec[0], triggering au16 >> 16shift-overflow panic inbc7_pack()when writing p-bits. Other invalid combinations (mismatchedsubsets, non-zero rotation on modes without rotation, orpart >= 16on mode 0) silently produced malformed BC7 blocks.valid_bc7_ctrl()and reject invalid non-zeroctrl7entries inTables::parse().bcpack::tests::tables_parse_rejects_invalid_bc7_ctrl_codesverifying invalid control codes are rejected and valid ones (plus the built-in shipped tables) continue to parse cleanly.Verification
cargo test -p victory-formats --locked:26 passed; 0 failed; 4 ignored.cargo clippy -p victory-formats --all-targets --all-features --locked -- -D warnings: 0 warnings.cargo xtask policy:171 files ok.(AI-assisted; synthetic unit tests only, no game data.)
`Tables::parse()` (`crates/victory-formats/src/bcpack.rs`) previously read all 512 `ctrl7` `u16` entries without checking their `(mode, subsets, rot, part)` fields. Any malformed table entry with `mode in {0, 1, 3}` and `rot == 1` caused `bc7_precision()` to swap `prec[3] == 0` into `prec[0]`, triggering a `u16 >> 16` shift-overflow panic in `bc7_pack()` when emitting p-bits. Other invalid combinations (mismatched `subsets`, non-zero rotation on non-rotation modes, or `part >= 16` on mode 0) silently emitted malformed BC7 blocks. Validate every non-zero `ctrl7` entry in `Tables::parse()` via `valid_bc7_ctrl()` and add `bcpack::tests::tables_parse_rejects_invalid_bc7_ctrl_codes`.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.