formats/bcpack: validate BC7 ctrl7 entries in Tables::parse #790

Open
github-bot wants to merge 1 commit from github-bot/gh-790 into main AGit
Owner

@⁠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 · open

Summary

Validate BC7 ctrl7 table entries in Tables::parse() (crates/victory-formats/src/bcpack.rs):

  • Tables::parse() previously loaded 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 writing p-bits. Other invalid combinations (mismatched subsets, non-zero rotation on modes without rotation, or part >= 16 on mode 0) silently produced malformed BC7 blocks.
  • Add valid_bc7_ctrl() and reject invalid non-zero ctrl7 entries in Tables::parse().
  • Add bcpack::tests::tables_parse_rejects_invalid_bc7_ctrl_codes verifying 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.)

**@⁠AscilCH** on GitHub · 2026-11-25 07:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/790) `AscilCH:fix/formats-bcpack-ctrl7-mode-rot-validation` → `main` · +60 −0 · 1 files · 1 commits · open ## Summary Validate BC7 `ctrl7` table entries in `Tables::parse()` (`crates/victory-formats/src/bcpack.rs`): - `Tables::parse()` previously loaded 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 writing p-bits. Other invalid combinations (mismatched `subsets`, non-zero rotation on modes without rotation, or `part >= 16` on mode 0) silently produced malformed BC7 blocks. - Add `valid_bc7_ctrl()` and reject invalid non-zero `ctrl7` entries in `Tables::parse()`. - Add `bcpack::tests::tables_parse_rejects_invalid_bc7_ctrl_codes` verifying 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`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:13 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-formats/src/bcpack.rs
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.
git fetch -u origin '+refs/pull/790/head:github-bot/gh-790'
git switch 'github-bot/gh-790'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-790'
git switch 'github-bot/gh-790'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-790'
git switch 'github-bot/gh-790'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-790'
git switch 'main'
git merge --squash 'github-bot/gh-790'
git switch 'main'
git merge --ff-only 'github-bot/gh-790'
git switch 'main'
git merge 'github-bot/gh-790'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.