Shaders: reject a dxbc part inside the header or part table #1942

Open
imjustprism wants to merge 1 commit from upstream-pr/1944 into main
imjustprism commented 2026-11-25 01:32:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by imjustprism on 2026-11-25T01:32:53Z.


a part offset that points into the container header or the offset table was accepted: offset 0 came back as a part with the container magic as its fourcc. parts follow the table, so an offset before its end is now refused as malformed. #343 refuses parts that overlap each other, which does not catch this.

the reporter had the same check on a fork and could not open a pull request; this one is written against current main, with a test for the header case and the table case. both fail without the check.

fixes #777

<!-- greyfinch-sync:Marvisak/VIctory:issue:5483383810 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1944). Originally posted by [imjustprism](https://github.com/imjustprism) on 2026-11-25T01:32:53Z. --- a part offset that points into the container header or the offset table was accepted: offset 0 came back as a part with the container magic as its fourcc. parts follow the table, so an offset before its end is now refused as malformed. #343 refuses parts that overlap each other, which does not catch this. the reporter had the same check on a fork and could not open a pull request; this one is written against current main, with a test for the header case and the table case. both fail without the check. fixes #777
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:35:24Z.


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

  • cargo test -p victory-shader --locked: 145 passed, 0 failed, 2 ignored. All tests pass.
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: 4 errors in test code (unused imports, unused variable, dead field rovs), but these are pre-existing on main — they fail identically on ccfb029 without this PR. The PR introduces no new clippy warnings.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149722417 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1944#issuecomment-7149722417). Originally posted by [Headache3318](https://github.com/Headache3318) on 2026-11-25T01:35:24Z. --- Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `cba87ae` applied cleanly onto current `main` `ccfb029`. - `cargo test -p victory-shader --locked`: 145 passed, 0 failed, 2 ignored. All tests pass. - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: 4 errors in test code (unused imports, unused variable, dead field `rovs`), but these are **pre-existing on main** — they fail identically on `ccfb029` without this PR. The PR introduces no new clippy warnings. Not tested: Windows MSVC build, the title itself. AI-assisted.
catminou4 commented 2026-11-25 03:05:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:05:24Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

145 passed / 0 failed / 2 ignored. DXBC parts inside the header/part table rejected (+1 test) — container-validation hardening against malformed shaders.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051251848 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1944#pullrequestreview-6051251848). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:05:24Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 145 passed / 0 failed / 2 ignored. DXBC parts inside the header/part table rejected (+1 test) — container-validation hardening against malformed shaders.
Marvisak commented 2026-11-25 09:06:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:20:29Z.


Automated triage for the maintainers.

Merge candidate.

Container::parse in crates/victory-shader/src/dxbc.rs now refuses a part whose offset lies before the end of the offset table (HEADER_SIZE + 4 * count). This fixes #777, which is labelled confirmed.

On main, offset 0 is accepted as a part tagged DXBC. The new test covers both the header case and the table case and checks the exact error. It uses the existing build helper. The table itself is already bounds-checked by u32_at on the slice cut to the container's size, so this is the remaining gap from #777.

CI: check passes.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156905434 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1944#issuecomment-7156905434). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:20:29Z. --- <!-- victory-triage v1 head=afc4f79123a7c0adecdabb004db084ce4ae9c79a verdict=merge-candidate at=2026-11-25T08:20:21Z --> Automated triage for the maintainers. **Merge candidate.** `Container::parse` in `crates/victory-shader/src/dxbc.rs` now refuses a part whose offset lies before the end of the offset table (`HEADER_SIZE + 4 * count`). This fixes #777, which is labelled confirmed. On `main`, offset 0 is accepted as a part tagged `DXBC`. The new test covers both the header case and the table case and checks the exact error. It uses the existing `build` helper. The table itself is already bounds-checked by `u32_at` on the slice cut to the container's size, so this is the remaining gap from #777. CI: `check` passes. --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 12:03:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T11:16:27Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head afc4f791 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160827756 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1944#issuecomment-7160827756). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T11:16:27Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head afc4f791 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
fuzeofficlal commented 2026-11-26 01:04:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:02:59Z.


Code review and Windows 11 verification at head afc4f79123a7 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-shader/src/dxbc.rs:88-95):
    • Validates count <= MAX_PARTS (256) before computing table_end = HEADER_SIZE + 4 * count (bounded <= 1056, overflow-free), lets u32_at reject truncated tables, and rejects any part with offset < table_end ("part inside the header or table"). Subsequent data.get(...) bounds checking remains intact.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
    • victory-shader --lib -- dxbc::: 3/3 passed (including rejects_a_part_inside_the_header_or_the_part_table).

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179378560 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1944#issuecomment-7179378560). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:02:59Z. --- Code review and Windows 11 verification at head `afc4f79123a7` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-shader/src/dxbc.rs:88-95`)**: - Validates `count <= MAX_PARTS` (`256`) before computing `table_end = HEADER_SIZE + 4 * count` (bounded `<= 1056`, overflow-free), lets `u32_at` reject truncated tables, and rejects any part with `offset < table_end` (`"part inside the header or table"`). Subsequent `data.get(...)` bounds checking remains intact. - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-shader --tests -- -D warnings`: 0 warnings - `victory-shader --lib -- dxbc::`: **3/3 passed** (including `rejects_a_part_inside_the_header_or_the_part_table`). LGTM.
upstream-sync changed title from [PR #1944] reject a dxbc part inside the header or part table to [PR #1944] Shaders: reject a dxbc part inside the header or part table 2026-11-26 09:05:10 +00:00
fuzeofficlal commented 2026-11-26 13:24:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T13:24:51Z.

Review: APPROVED


Reviewed and verified afc4f79123a7 and merged onto origin/main (63bcca43; clean git merge-tree):

  • The lower-bound check in crates/victory-shader/src/dxbc.rs:86-95 is right: with count <= MAX_PARTS (256), table_end = HEADER_SIZE + 4 * count cannot overflow, and rejecting offset < table_end prevents parts from aliasing the DXBC header or offset table while keeping count == 0, offset == table_end, and zero-length part bodies valid. The new regression test covers both header and table offsets. (Existing offset + 4 / offset + 8 + size arithmetic could move to checked addition in a follow-up if 32-bit overflow-checked builds are targeted.)

Local verification: rustfmt --edition 2024 --check crates/victory-shader/src/dxbc.rs, xtask policy (182 files ok), cargo clippy -p victory-shader --all-targets (default and --all-features), dxbc:: tests (3 passed), and the merged non-GPU victory-shader unit suite (162 passed, 0 failed, 2 ignored) all pass.

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074902292 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1944#pullrequestreview-6074902292). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T13:24:51Z. **Review:** APPROVED --- Reviewed and verified `afc4f79123a7` and merged onto `origin/main` (`63bcca43`; clean `git merge-tree`): - The lower-bound check in `crates/victory-shader/src/dxbc.rs:86-95` is right: with `count <= MAX_PARTS` (`256`), `table_end = HEADER_SIZE + 4 * count` cannot overflow, and rejecting `offset < table_end` prevents parts from aliasing the DXBC header or offset table while keeping `count == 0`, `offset == table_end`, and zero-length part bodies valid. The new regression test covers both header and table offsets. (Existing `offset + 4` / `offset + 8 + size` arithmetic could move to checked addition in a follow-up if 32-bit overflow-checked builds are targeted.) Local verification: `rustfmt --edition 2024 --check crates/victory-shader/src/dxbc.rs`, `xtask policy` (`182 files ok`), `cargo clippy -p victory-shader --all-targets` (`default` and `--all-features`), `dxbc::` tests (`3 passed`), and the merged non-GPU `victory-shader` unit suite (`162 passed, 0 failed, 2 ignored`) all pass. LGTM.
Dukestar69 commented 2026-11-26 23:28:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T23:28:44Z.

Review: APPROVED


LGTM — verified on Windows against origin/main (63bcca4).

  • Rejecting DXBC parts whose offset overlaps the container header or part offset table cleanly prevents malformed self-overlapping containers from parsing.
  • cargo test -p victory-shader --lib dxbc:: -- --test-threads=1: all passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6081461014 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1944#pullrequestreview-6081461014). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T23:28:44Z. **Review:** APPROVED --- LGTM — verified on Windows against `origin/main` (`63bcca4`). - Rejecting DXBC parts whose offset overlaps the container header or part offset table cleanly prevents malformed self-overlapping containers from parsing. - `cargo test -p victory-shader --lib dxbc:: -- --test-threads=1`: all passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/1944:upstream-pr/1944'
git switch 'upstream-pr/1944'

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