Shaders: bounds-check DXIL header offsets and recognize dword zero padding #1303

Open
geiyiliyabumo wants to merge 1 commit from upstream-pr/1303 into main
geiyiliyabumo commented 2026-11-24 17:17:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T17:17:23Z.


Summary

Audits \crates/victory-shader/src/dxil.rs\ and fixes two parser/layout issues:

  • Replaces unchecked header-relative offset and bitcode length additions with checked slice splits, eliminating overflow risk on 32-bit targets and malformed inputs.
  • Recognizes exact zero padding up to a 4-byte dword boundary as standard PC layout per LLVM's \MCDXContainerWriter, while preserving the raw trailer bytes.
  • Adds 4 deterministic synthetic unit tests covering wire bytes, all four alignment residues, extra trailer data, truncation, and boundary values.

Verification

  • \cargo test -p victory-shader --lib dxil\ ? 7 passed, 0 failed
  • \cargo clippy -p victory-shader --all-targets -- -D warnings\ ? clean
  • \cargo xtask policy\ ? 154 files ok

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587414434 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1303). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T17:17:23Z. --- ## Summary Audits \crates/victory-shader/src/dxil.rs\ and fixes two parser/layout issues: - Replaces unchecked header-relative offset and bitcode length additions with checked slice splits, eliminating overflow risk on 32-bit targets and malformed inputs. - Recognizes exact zero padding up to a 4-byte dword boundary as standard PC layout per LLVM's \MCDXContainerWriter\, while preserving the raw trailer bytes. - Adds 4 deterministic synthetic unit tests covering wire bytes, all four alignment residues, extra trailer data, truncation, and boundary values. ## Verification - \cargo test -p victory-shader --lib dxil\ ? 7 passed, 0 failed - \cargo clippy -p victory-shader --all-targets -- -D warnings\ ? clean - \cargo xtask policy\ ? 154 files ok *AI-assisted; synthetic tests only, no game files.*
catminou4 commented 2026-11-24 21:02:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:43Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 100 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.

Bounds-checks DXIL header offsets with split_at_checked (no more start+len overflow) and treats dword-zero padding as trailer: is_standard_layout now accepts exactly the zero padding to a dword boundary and rejects any other trailer byte. Tests cover every truncation length, invalid header fields, and all four padding lengths.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046556058 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1303#pullrequestreview-6046556058). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:09:43Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 100 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests. Bounds-checks DXIL header offsets with split_at_checked (no more start+len overflow) and treats dword-zero padding as trailer: is_standard_layout now accepts exactly the zero padding to a dword boundary and rejects any other trailer byte. Tests cover every truncation length, invalid header fields, and all four padding lengths.
Marvisak commented 2026-11-25 03:03:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T02:34:16Z.


Automated triage for the maintainers. Thank you for the careful tests, but this adds guards for cases that cannot occur. VIctory builds only for x86_64-pc-windows-msvc (rust-toolchain.toml), and on 64-bit usize, 8 + offset + len from two u32 fields cannot overflow; out-of-range values were already rejected by the existing get(..). LLVM's bitstream writer emits whole 32-bit words, so DXIL bitcode never needs the 1-3 bytes of padding that is_standard_layout would now accept. Also, nothing in the workspace calls DxilProgram::parse except its own tests in crates/victory-shader/src/dxil.rs, so behaviour does not change. A malformed input that main handles wrongly, or a caller that needs the change, would change this verdict. This PR 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:7150893726 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1303#issuecomment-7150893726). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T02:34:16Z. --- <!-- victory-triage v1 head=428725aaed223953709bcc7d526f3070a424587d verdict=proposed-close at=2026-11-25T02:20:29Z --> Automated triage for the maintainers. Thank you for the careful tests, but this adds guards for cases that cannot occur. VIctory builds only for `x86_64-pc-windows-msvc` (`rust-toolchain.toml`), and on 64-bit `usize`, `8 + offset + len` from two `u32` fields cannot overflow; out-of-range values were already rejected by the existing `get(..)`. LLVM's bitstream writer emits whole 32-bit words, so DXIL bitcode never needs the 1-3 bytes of padding that `is_standard_layout` would now accept. Also, nothing in the workspace calls `DxilProgram::parse` except its own tests in `crates/victory-shader/src/dxil.rs`, so behaviour does not change. A malformed input that `main` handles wrongly, or a caller that needs the change, would change this verdict. This PR 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/1303:upstream-pr/1303'
git switch 'upstream-pr/1303'

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