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

Open
AscilCH wants to merge 1 commit from upstream-pr/790 into main
AscilCH commented 2026-11-25 07:35:43 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T07:35:43Z.


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.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6599580118 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/790). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T07:35:43Z. --- ## 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.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/790:upstream-pr/790'
git switch 'upstream-pr/790'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/790'
git switch 'upstream-pr/790'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/790'
git switch 'upstream-pr/790'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/790'
git switch 'main'
git merge --squash 'upstream-pr/790'
git switch 'main'
git merge --ff-only 'upstream-pr/790'
git switch 'main'
git merge 'upstream-pr/790'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!790
No description provided.