Shaders: reject DXBC part offsets inside the header or part table #3249

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3251 into main
andrewpozdnakov7-jpg commented 2026-11-26 14:38:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T14:38:04Z.


Container::parse reads each part offset from the table and uses it without checking that it lies past the header and the table itself. An offset of 0 reads the container magic back as a part FourCC (DXBC), and an offset inside the table reads neighbour entries as a part header.

The table has to fit inside the container, and every part now has to start at or after HEADER_SIZE + 4 * count. Anything earlier is Malformed("part offset inside the header or part table").

  • rejects_part_offsets_inside_the_header_or_table covers offset 0 and an offset landing inside the table; cargo test -p victory-shader --lib dxbc: 3 passed.
  • Full victory-shader suite with app-local WARP SM 6.6 and active DXIL validation: 300 passed, 3 failed, 3 ignored. The same three fail on 63bcca4 without this change (299 passed, 3 failed, 3 ignored): wave64_permutes_stay_within_each_32_lane_half, permutes_read_the_lane_named_and_zero_from_lanes_left_out, edge_flagged_triangles_draw_as_unflagged_ones, all warp assertions this machine produces.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean. cargo xtask policy: 192 files ok.

Valid containers are unaffected: every real part starts after the table, which the round-trip test keeps covering.

Fixes #777.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5511988015 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3251). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T14:38:04Z. --- `Container::parse` reads each part offset from the table and uses it without checking that it lies past the header and the table itself. An offset of 0 reads the container magic back as a part FourCC (`DXBC`), and an offset inside the table reads neighbour entries as a part header. The table has to fit inside the container, and every part now has to start at or after `HEADER_SIZE + 4 * count`. Anything earlier is `Malformed("part offset inside the header or part table")`. - `rejects_part_offsets_inside_the_header_or_table` covers offset 0 and an offset landing inside the table; `cargo test -p victory-shader --lib dxbc`: 3 passed. - Full `victory-shader` suite with app-local WARP SM 6.6 and active DXIL validation: 300 passed, 3 failed, 3 ignored. The same three fail on `63bcca4` without this change (299 passed, 3 failed, 3 ignored): `wave64_permutes_stay_within_each_32_lane_half`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`, `edge_flagged_triangles_draw_as_unflagged_ones`, all `warp` assertions this machine produces. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. `cargo xtask policy`: 192 files ok. Valid containers are unaffected: every real part starts after the table, which the round-trip test keeps covering. Fixes #777.
Dukestar69 commented 2026-11-26 14:49:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T14:49:53Z.

Review: APPROVED


Reviewed the diff and verified locally on Windows 11 x64:

  • Validating data.len() >= table_end and offset >= table_end in Container::parse cleanly rejects malformed DXBC part offsets that point into the header or part offset table.
  • cargo test -p victory-shader --lib dxbc:: -- --test-threads=1: 3 passed, 0 failed (including
    ejects_part_offsets_inside_the_header_or_table).
  • 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:6076169768 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3251#pullrequestreview-6076169768). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T14:49:53Z. **Review:** APPROVED --- Reviewed the diff and verified locally on Windows 11 x64: - Validating data.len() >= table_end and offset >= table_end in Container::parse cleanly rejects malformed DXBC part offsets that point into the header or part offset table. - cargo test -p victory-shader --lib dxbc:: -- --test-threads=1: 3 passed, 0 failed (including ejects_part_offsets_inside_the_header_or_table). - 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).
fuzeofficlal commented 2026-11-26 22:29:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:29:00Z.

Review: APPROVED


Verified on 8d5898b7:

  • rustfmt --edition 2024 --check crates/victory-shader/src/dxbc.rs: clean.
  • cargo xtask policy: 191 files ok.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features): clean.
  • cargo test --locked -p victory-shader --lib dxbc::: 3 passed, 0 failed (including rejects_part_offsets_inside_the_header_or_table).

With count <= 256, table_end = HEADER_SIZE + 4 * count (<= 1,056) cannot overflow, data.len() < table_end rejects truncated part tables against the declared container slice, and offset < table_end cleanly rejects offsets pointing into the 32-byte header or part table while keeping zero-part containers and parts starting at table_end working. (Minor non-blocking note: adding a unit test where data.len() < table_end and using checked additions on offset + 4 / offset + 8 + size at dxbc.rs:102, 109 for 32-bit targets would harden the remaining boundary paths.) LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6081128834 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3251#pullrequestreview-6081128834). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T22:29:00Z. **Review:** APPROVED --- Verified on `8d5898b7`: - `rustfmt --edition 2024 --check crates/victory-shader/src/dxbc.rs`: clean. - `cargo xtask policy`: `191 files ok`. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`): clean. - `cargo test --locked -p victory-shader --lib dxbc::`: **3 passed, 0 failed** (including `rejects_part_offsets_inside_the_header_or_table`). With `count <= 256`, `table_end = HEADER_SIZE + 4 * count` (`<= 1,056`) cannot overflow, `data.len() < table_end` rejects truncated part tables against the declared container slice, and `offset < table_end` cleanly rejects offsets pointing into the 32-byte header or part table while keeping zero-part containers and parts starting at `table_end` working. (Minor non-blocking note: adding a unit test where `data.len() < table_end` and using checked additions on `offset + 4` / `offset + 8 + size` at `dxbc.rs:102, 109` for 32-bit targets would harden the remaining boundary paths.) LGTM.
Jackster commented 2026-11-26 22:29:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:29:04Z.


Windows 11, 63bcca4 + this PR:

  • cargo test -p victory-shader --lib dxbc::: 3 passed / 0 failed.
  • dxbc::tests::rejects_part_offsets_inside_the_header_or_table by name: 1 passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

The test covers both the offset that names the container magic (0, which the old parser read back as the DXBC part FourCC) and an offset inside the part table, each expecting ShaderError::Malformed("part offset inside the header or part table"). Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204718701 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3251#issuecomment-7204718701). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T22:29:04Z. --- Windows 11, `63bcca4` + this PR: - `cargo test -p victory-shader --lib dxbc::`: 3 passed / 0 failed. - `dxbc::tests::rejects_part_offsets_inside_the_header_or_table` by name: 1 passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. The test covers both the offset that names the container magic (`0`, which the old parser read back as the `DXBC` part FourCC) and an offset inside the part table, each expecting `ShaderError::Malformed("part offset inside the header or part table")`. Synthetic only. AI-assisted.
futurepro62 commented 2026-11-26 23:02:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T23:02:33Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, Jackster, fuzeofficlal, since none of them names a GPU run. Tested exact head 8d5898b (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: rejects_part_offsets_inside_the_header_or_table.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7205203061 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3251#issuecomment-7205203061). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T23:02:33Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, Jackster, fuzeofficlal, since none of them names a GPU run. Tested exact head `8d5898b` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `rejects_part_offsets_inside_the_header_or_table`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
cloph-dsp commented 2026-11-27 01:23:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T01:23:15Z.


Independent local verification of PR #3251 (head 8d5898b7f6f57135bc0ed258a8fec995546f94d4), Windows / Rust 1.100.0 / MSVC, worktree-local CARGO_TARGET_DIR, CARGO_BUILD_JOBS=2, synthetic source only, no game data.

Command:
cargo test --locked -p victory-shader --lib -- dxbc::tests::rejects_part_offsets_inside_the_header_or_table --exact --test-threads=1 --quiet

Result: running 1 test, test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out.

git diff --check 63bcca43c6a00a758510398fa43096ce7e4f7df0 HEAD (the real merge base) exits 0. The new test name is absent from origin/main (git grep found 0 hits), confirming the test is added by this PR. Against current origin/main an unrelated trailing blank line in crates/victory-formats/src/xma/tables.rs pollutes diff --check, so the merge base was used.

Only the named test was run; the full crate suite was not exercised. GPU/driver: N/A (CPU-only shader parsing). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM were used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7207245970 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3251#issuecomment-7207245970). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T01:23:15Z. --- Independent local verification of PR #3251 (head `8d5898b7f6f57135bc0ed258a8fec995546f94d4`), Windows / Rust 1.100.0 / MSVC, worktree-local `CARGO_TARGET_DIR`, `CARGO_BUILD_JOBS=2`, synthetic source only, no game data. Command: `cargo test --locked -p victory-shader --lib -- dxbc::tests::rejects_part_offsets_inside_the_header_or_table --exact --test-threads=1 --quiet` Result: `running 1 test`, `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out`. `git diff --check 63bcca43c6a00a758510398fa43096ce7e4f7df0 HEAD` (the real merge base) exits 0. The new test name is absent from `origin/main` (`git grep` found 0 hits), confirming the test is added by this PR. Against current `origin/main` an unrelated trailing blank line in `crates/victory-formats/src/xma/tables.rs` pollutes `diff --check`, so the merge base was used. Only the named test was run; the full crate suite was not exercised. GPU/driver: N/A (CPU-only shader parsing). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM were used.
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/3251:upstream-pr/3251'
git switch 'upstream-pr/3251'

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