Validate BC7 control-word subset counts #1556

Open
oddmaniv wants to merge 1 commit from upstream-pr/1557 into main
oddmaniv commented 2026-11-24 19:10:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oddmaniv on 2026-11-24T19:10:12Z.


Summary

Validate nonzero BC7 control words while parsing BCPack tables: modes 0–7 must encode subset counts [3, 2, 3, 2, 1, 1, 1, 2]. Keep the all-zero control word valid as the existing sentinel.

The regression test uses synthetic tables and exercises subset counts 0–3 for every mode, accepting each mode's required count and rejecting the other nonzero controls with the parser's specific validation error. It also verifies the zero sentinel. This is defensive validation for malformed/caller-supplied table data; shipped nonzero controls are valid, and no title-data failure or gameplay improvement is demonstrated.

Verification

  • rustfmt --check --edition 2024 crates/victory-formats/src/bcpack.rs
  • cargo test --locked -p victory-formats — 24 passed, 0 failed, 4 ignored.
  • cargo clippy --locked -p victory-formats --all-targets -- -D warnings
  • cargo clippy --locked -p victory-formats --all-targets --all-features -- -D warnings
  • cargo xtask policy — 154 files accepted.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6589387696 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1557). Originally posted by [oddmaniv](https://github.com/oddmaniv) on 2026-11-24T19:10:12Z. --- ## Summary Validate nonzero BC7 control words while parsing BCPack tables: modes 0–7 must encode subset counts `[3, 2, 3, 2, 1, 1, 1, 2]`. Keep the all-zero control word valid as the existing sentinel. The regression test uses synthetic tables and exercises subset counts 0–3 for every mode, accepting each mode's required count and rejecting the other nonzero controls with the parser's specific validation error. It also verifies the zero sentinel. This is defensive validation for malformed/caller-supplied table data; shipped nonzero controls are valid, and no title-data failure or gameplay improvement is demonstrated. ## Verification - `rustfmt --check --edition 2024 crates/victory-formats/src/bcpack.rs` - `cargo test --locked -p victory-formats` — 24 passed, 0 failed, 4 ignored. - `cargo clippy --locked -p victory-formats --all-targets -- -D warnings` - `cargo clippy --locked -p victory-formats --all-targets --all-features -- -D warnings` - `cargo xtask policy` — 154 files accepted.
catminou4 commented 2026-11-24 20:02:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:20:57Z.

Review: APPROVED


BC7 control-word validation: subset count (c & 0xff) >> 6 must match the mode's partition count [3,2,3,2,1,1,1,2] (checked against the BC7 spec), with c == 0 kept as the valid sentinel. The test sweeps all 8 modes × 4 subset counts against synthetic tables, including the sentinel. cargo test -p victory-formats --locked on macOS arm64: 24 passed, 0 failed (+1).

<!-- greyfinch-sync:Marvisak/VIctory:review:6045811727 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1557#pullrequestreview-6045811727). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T19:20:57Z. **Review:** APPROVED --- BC7 control-word validation: subset count `(c & 0xff) >> 6` must match the mode's partition count `[3,2,3,2,1,1,1,2]` (checked against the BC7 spec), with `c == 0` kept as the valid sentinel. The test sweeps all 8 modes × 4 subset counts against synthetic tables, including the sentinel. `cargo test -p victory-formats --locked` on macOS arm64: 24 passed, 0 failed (+1).
mercuryVM commented 2026-11-24 20:02:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T19:46:07Z.

Review: APPROVED


Tested 1504ec9 on Windows 11, RTX 5070, MSVC: builds, cargo test --workspace --no-fail-fast 612 passed, 0 failed (on our fork main). The new test passes.

  • The subset table [3, 2, 3, 2, 1, 1, 1, 2] is the BC7 per-mode subset count, and the zero sentinel stays accepted.
  • I checked that the shipped tables still parse: the_shipped_tables_parse (which loads bcpack-tables.bin) and the decode tests built on Tables::builtin() pass. So this only turns malformed or caller-supplied tables into an error instead of a later wrong decode.
  • The description is careful not to claim a gameplay effect, which matches what the change does.

Merged into our fork's main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6046196345 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1557#pullrequestreview-6046196345). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T19:46:07Z. **Review:** APPROVED --- Tested 1504ec9 on Windows 11, RTX 5070, MSVC: builds, `cargo test --workspace --no-fail-fast` 612 passed, 0 failed (on our fork main). The new test passes. - The subset table `[3, 2, 3, 2, 1, 1, 1, 2]` is the BC7 per-mode subset count, and the zero sentinel stays accepted. - I checked that the shipped tables still parse: `the_shipped_tables_parse` (which loads `bcpack-tables.bin`) and the decode tests built on `Tables::builtin()` pass. So this only turns malformed or caller-supplied tables into an error instead of a later wrong decode. - The description is careful not to claim a gameplay effect, which matches what the change does. Merged into our fork's main. AI-assisted (Claude Code).
tdogghockey commented 2026-11-24 20:03:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tdogghockey on 2026-11-24T19:22:25Z.


I independently verified this PR at head 1504ec9 on aarch64 Linux.

  • cargo test --offline -p victory-formats --locked bc7_control_subset_counts — 1 passed
  • cargo test --offline -p victory-formats --locked — 24 passed, 0 failed, 4 ignored
  • cargo clippy --offline -p victory-formats --all-targets --locked -- -D warnings — clean
  • rustfmt --edition 2024 --check crates/victory-formats/src/bcpack.rs — clean

I also checked the new validation against the decoder's use of ctrl7: mode/subset extraction matches bc7/bc7_precision (ctrl & 7, (ctrl & 0xff) >> 6), so rotation/precision bits above the subset field are not rejected, and the_shipped_tables_parse still passes.

No correctness issue found in the host-independent code. Scope note: I did not run Windows/GPU tests or CI. No approval implied.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142001833 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1557#issuecomment-7142001833). Originally posted by [tdogghockey](https://github.com/tdogghockey) on 2026-11-24T19:22:25Z. --- I independently verified this PR at head `1504ec9` on aarch64 Linux. - `cargo test --offline -p victory-formats --locked bc7_control_subset_counts` — 1 passed - `cargo test --offline -p victory-formats --locked` — 24 passed, 0 failed, 4 ignored - `cargo clippy --offline -p victory-formats --all-targets --locked -- -D warnings` — clean - `rustfmt --edition 2024 --check crates/victory-formats/src/bcpack.rs` — clean I also checked the new validation against the decoder's use of `ctrl7`: mode/subset extraction matches `bc7`/`bc7_precision` (`ctrl & 7`, `(ctrl & 0xff) >> 6`), so rotation/precision bits above the subset field are not rejected, and `the_shipped_tables_parse` still passes. No correctness issue found in the host-independent code. Scope note: I did not run Windows/GPU tests or CI. No approval implied.
Headache3318 commented 2026-11-25 02:06:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-25T01:34:19Z.


Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head 1504ec9 applied cleanly onto current main ccfb029.

  • cargo test --locked -p victory-formats: 24 passed, 0 failed, 4 ignored. The new BC7 control-word validation test passes.
  • cargo clippy -p victory-formats --all-targets --all-features --locked -- -D warnings: clean.

Not tested: Windows MSVC build, the title itself. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149700979 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1557#issuecomment-7149700979). Originally posted by [Headache3318](https://github.com/Headache3318) on 2026-11-25T01:34:19Z. --- Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `1504ec9` applied cleanly onto current `main` `ccfb029`. - `cargo test --locked -p victory-formats`: 24 passed, 0 failed, 4 ignored. The new BC7 control-word validation test passes. - `cargo clippy -p victory-formats --all-targets --all-features --locked -- -D warnings`: clean. Not tested: Windows MSVC build, the title itself. AI-assisted.
Marvisak commented 2026-11-25 04:06:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:18:47Z.


Automated triage for the maintainers.

Proposed close: a guard for a case that does not occur. The new check in Tables::parse (crates/victory-formats/src/bcpack.rs) rejects control words whose subset count differs from the BC7 mode's. As the description says, the shipped tables have no such word and no failure is shown. The decoder in main does not need the check to stay safe: bc7 already refuses a zero control word, reads mode and subsets from the word, and only walks take(subsets) rows of fixed-size arrays. A mismatched word would decode wrongly, but cannot read out of bounds. A table that triggered the check would also make the whole parse fail rather than only the affected blocks.

This pull request will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151796111 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1557#issuecomment-7151796111). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:18:47Z. --- <!-- victory-triage v1 head=1504ec9aa4465bfe99dcf9311ea0b5091ef1a892 verdict=proposed-close at=2026-11-25T03:24:30Z --> Automated triage for the maintainers. **Proposed close: a guard for a case that does not occur.** The new check in `Tables::parse` (`crates/victory-formats/src/bcpack.rs`) rejects control words whose subset count differs from the BC7 mode's. As the description says, the shipped tables have no such word and no failure is shown. The decoder in `main` does not need the check to stay safe: `bc7` already refuses a zero control word, reads `mode` and `subsets` from the word, and only walks `take(subsets)` rows of fixed-size arrays. A mismatched word would decode wrongly, but cannot read out of bounds. A table that triggered the check would also make the whole parse fail rather than only the affected blocks. This pull request will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
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/1557:upstream-pr/1557'
git switch 'upstream-pr/1557'

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/1557'
git switch 'upstream-pr/1557'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1557'
git switch 'upstream-pr/1557'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1557'
git switch 'main'
git merge --squash 'upstream-pr/1557'
git switch 'main'
git merge --ff-only 'upstream-pr/1557'
git switch 'main'
git merge 'upstream-pr/1557'
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
Marvisak/VIctory!1556
No description provided.