Shaders: fix 4 DXIL validator bugs and add synthetic container/validator tests #1202

Closed
geiyiliyabumo wants to merge 2 commits from upstream-pr/1202 into main
geiyiliyabumo commented 2026-11-24 16:24:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T16:24:52Z.


Summary

Closes #1049

Full verification details and change notes are documented in #1049 (commit 9ffb7a1, based on main ffe310e).

 crates/victory-shader/src/emit/container.rs | 309 ++++++++++++++++++++
 crates/victory-shader/src/emit/validator.rs | 427 ++++++++++++++++++++++++++--
 2 files changed, 719 insertions(+), 17 deletions(-)

Verification (Windows 11 x64 MSVC)

  • rustfmt --edition 2024 --check on edited files: PASS
  • cargo xtask policy: PASS (zero game files/data)
  • cargo clippy --all-targets --locked -- -D warnings (default + --features diagnostics where applicable): PASS
  • Targeted & crate unit/GPU tests: PASS

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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6586449168 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1202). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T16:24:52Z. --- ### Summary Closes #1049 Full verification details and change notes are documented in #1049 (commit `9ffb7a1`, based on `main` `ffe310e`). ```text crates/victory-shader/src/emit/container.rs | 309 ++++++++++++++++++++ crates/victory-shader/src/emit/validator.rs | 427 ++++++++++++++++++++++++++-- 2 files changed, 719 insertions(+), 17 deletions(-) ``` ### Verification (Windows 11 x64 MSVC) - `rustfmt --edition 2024 --check` on edited files: **PASS** - `cargo xtask policy`: **PASS** (zero game files/data) - `cargo clippy --all-targets --locked -- -D warnings` (default + `--features diagnostics` where applicable): **PASS** - Targeted & crate unit/GPU tests: **PASS** *AI-assisted; synthetic tests only, no game files.*
fuzeofficlal commented 2026-11-24 17:04:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T16:56:03Z.


Tested Validator against the Windows SDK dxil.dll and found two additional live-DLL edge cases worth folding in alongside the COM/module lifetime fixes:

  1. STATUS_ACCESS_VIOLATION (0xc0000005) inside dxil.dll on truncated "DXBC..." blobs: IDxcValidator::Validate trusts DxilContainerHeader::ContainerSizeInBytes and PartCount at offsets 24/28 before checking IDxcBlob::GetBufferSize(), reading out of bounds on truncated or corrupt DXBC headers. Running if container.starts_with(b"DXBC") { crate::dxbc::Container::parse(container).map_err(|e| e.to_string())?; } up front catches malformed containers in safe Rust without affecting non-DXBC unit-test stubs.
  2. Trailing NUL in Validator::load error strings: String::from_utf16_lossy(&name) includes the appended 0 terminator ("cannot load ...\0"). Encoding with OsStrExt::encode_wide().chain([0]) and formatting target.to_string_lossy() keeps both non-UTF-8 paths and error strings clean.

Also verified container::hash in-place signing byte-for-byte against dxil.dll across all 64 len % 64 padding remainders (including the 55/56 two-block split). Reference commit: github.com/fuzeofficlal/VIctory@6a82a194cf

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138431797 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1202#issuecomment-7138431797). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T16:56:03Z. --- Tested `Validator` against the Windows SDK `dxil.dll` and found two additional live-DLL edge cases worth folding in alongside the COM/module lifetime fixes: 1. **`STATUS_ACCESS_VIOLATION` (`0xc0000005`) inside `dxil.dll` on truncated `"DXBC..."` blobs**: `IDxcValidator::Validate` trusts `DxilContainerHeader::ContainerSizeInBytes` and `PartCount` at offsets 24/28 before checking `IDxcBlob::GetBufferSize()`, reading out of bounds on truncated or corrupt `DXBC` headers. Running `if container.starts_with(b"DXBC") { crate::dxbc::Container::parse(container).map_err(|e| e.to_string())?; }` up front catches malformed containers in safe Rust without affecting non-`DXBC` unit-test stubs. 2. **Trailing NUL in `Validator::load` error strings**: `String::from_utf16_lossy(&name)` includes the appended `0` terminator (`"cannot load ...\0"`). Encoding with `OsStrExt::encode_wide().chain([0])` and formatting `target.to_string_lossy()` keeps both non-UTF-8 paths and error strings clean. Also verified `container::hash` in-place signing byte-for-byte against `dxil.dll` across all 64 `len % 64` padding remainders (including the 55/56 two-block split). Reference commit: https://github.com/fuzeofficlal/VIctory/commit/6a82a194cf1bdc045b8f74dce450a59be9dfadbf
geiyiliyabumo commented 2026-11-24 18:05:36 +00:00 (Migrated from github.com)

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


Thanks @fuzeofficlal for the live \dxil.dll\ edge-case review!

Folded both fixes into this PR:

  1. Pre-validate containers starting with \"DXBC"\ via \crate::dxbc::Container::parse(container)\ before invoking \IDxcValidator::Validate, catching truncated/corrupt DXBC headers in safe Rust instead of triggering \�xc0000005\ inside \dxil.dll\ while leaving non-DXBC unit-test stubs unaffected.
  2. Encode the DLL path via \OsStrExt::encode_wide().chain([0])\ and format \ arget.to_string_lossy()\ so \Validator::load\ error strings no longer include a trailing NUL.

Added regression tests for both (\load_error_has_no_trailing_nul, \ runcated_dxbc_container_is_rejected_before_calling_dxil). Re-verified \cargo test -p victory-shader --lib emit::validator\ (11/11 passed), \cargo clippy -p victory-shader --all-targets -- -D warnings, and \cargo xtask policy.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138931303 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1202#issuecomment-7138931303). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T17:15:48Z. --- Thanks @fuzeofficlal for the live \dxil.dll\ edge-case review! Folded both fixes into this PR: 1. Pre-validate containers starting with \"DXBC"\ via \crate::dxbc::Container::parse(container)\ before invoking \IDxcValidator::Validate\, catching truncated/corrupt DXBC headers in safe Rust instead of triggering \�xc0000005\ inside \dxil.dll\ while leaving non-DXBC unit-test stubs unaffected. 2. Encode the DLL path via \OsStrExt::encode_wide().chain([0])\ and format \ arget.to_string_lossy()\ so \Validator::load\ error strings no longer include a trailing NUL. Added regression tests for both (\load_error_has_no_trailing_nul\, \ runcated_dxbc_container_is_rejected_before_calling_dxil\). Re-verified \cargo test -p victory-shader --lib emit::validator\ (11/11 passed), \cargo clippy -p victory-shader --all-targets -- -D warnings\, and \cargo xtask policy\. *AI-assisted; synthetic tests only, no game files.*
Zipettte commented 2026-11-24 18:06:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T18:00:12Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 9ffb7a1: cargo test -p victory-shader passes, 137 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140015245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1202#issuecomment-7140015245). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T18:00:12Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 9ffb7a1: `cargo test -p victory-shader` passes, 137 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
upstream-sync closed this pull request 2026-11-25 01:05:55 +00:00
Marvisak commented 2026-11-25 01:08:04 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #477. The same validator fixes as #477 (GetStatus, empty error blob, FreeLibrary, NUL in the message) at twice the size, plus container tests that pin current output; its Psv test literal lacks the gs field main added, so it does not compile on main.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148660070 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1202#issuecomment-7148660070). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:34:51Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #477. The same validator fixes as #477 (GetStatus, empty error blob, FreeLibrary, NUL in the message) at twice the size, plus container tests that pin current output; its Psv test literal lacks the gs field main added, so it does not compile on main. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!1202
No description provided.