GPU: reject corrupted successful and refused shader-cache entries #3096

Open
yefan911 wants to merge 4 commits from upstream-pr/3098 into main
yefan911 commented 2026-11-26 07:52:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by yefan911 on 2026-11-26T07:52:51Z.


Follow-up to #1094 and the triage request to protect successful translations as well as refusals. A same-length edit to a serialized successful entry can otherwise return changed DXIL or metadata as a cache hit.

Both successful (VSH2) and refused (VSF3) shader-cache entries now carry a trailing BLAKE3 digest covering the complete serialized payload, including the marker. Decode checks the digest before interpreting fields, retains its structural checks, and treats damaged entries as cache misses so they are translated again. Refusal text must still be valid UTF-8.

The checksum belongs to this serialization layer: victory_pipeline::Cache stores opaque converter output and returns its raw path to callers. This keeps the cache API and atomic publication unchanged. It detects accidental damage; it does not establish how damage occurred or claim that VIctory's atomic rename normally publishes partial files.

The build fingerprint includes shader_cache.rs, so the encoding change selects a fresh cache namespace. Existing translated entries are rebuilt once. Successful entries gain a 32-byte digest, and cache hits verify the complete payload. No performance or gameplay improvement is claimed.

The all-entry integrity implementation is contributed by XeNS1, incorporated from yefan911/VIctory#1 while preserving commit 71de96199ef60e0bead2c0b19a778d8b76c274b4 and its authorship.

Validation on Windows x86-64 / Rust 1.98.1:

  • An external Cargo harness imports the actual shader_cache.rs and depends on the actual victory-shader and victory-pipeline crates, with no behavior stubs or GPU host feature. All seven cache-module tests pass, including mutation of every byte, truncation, appended data, correctly checksummed malformed fields, and on-disk corruption followed by retranslation and a cache hit.
  • cargo test -p victory-pipeline --locked: eight tests pass.
  • Strict all-target harness Clippy, changed-file rustfmt, and repository asset policy (191 files ok) pass.
  • cargo test -p victory-gpu --lib shader_cache:: --locked -- --test-threads=1 builds the full GPU test binary successfully, but that binary exits before starting the test harness with STATUS_ACCESS_VIOLATION (0xc0000005) on this machine. Full GPU-binary test execution is therefore still unverified here; the isolated module results above are reported separately.
  • The contributor also recorded Linux validation and a Windows-target compile check in the linked follow-up PR. Those are their results, separate from the native Windows checks above.

All new fixtures are synthetic. No game files, game assets, retail checks, or gameplay execution used. No dependencies or CI files changed. The follow-up's existing Windows CI approval was granted; this description does not claim that run has passed.

AI-assisted: GPT-6.1 Sol; community contribution retains its own attribution.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5506120282 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3098). Originally posted by [yefan911](https://github.com/yefan911) on 2026-11-26T07:52:51Z. --- Follow-up to #1094 and the triage request to protect successful translations as well as refusals. A same-length edit to a serialized successful entry can otherwise return changed DXIL or metadata as a cache hit. Both successful (`VSH2`) and refused (`VSF3`) shader-cache entries now carry a trailing BLAKE3 digest covering the complete serialized payload, including the marker. Decode checks the digest before interpreting fields, retains its structural checks, and treats damaged entries as cache misses so they are translated again. Refusal text must still be valid UTF-8. The checksum belongs to this serialization layer: `victory_pipeline::Cache` stores opaque converter output and returns its raw path to callers. This keeps the cache API and atomic publication unchanged. It detects accidental damage; it does not establish how damage occurred or claim that VIctory's atomic rename normally publishes partial files. The build fingerprint includes `shader_cache.rs`, so the encoding change selects a fresh cache namespace. Existing translated entries are rebuilt once. Successful entries gain a 32-byte digest, and cache hits verify the complete payload. No performance or gameplay improvement is claimed. The all-entry integrity implementation is contributed by **XeNS1**, incorporated from [yefan911/VIctory#1](https://github.com/yefan911/VIctory/pull/1) while preserving commit `71de96199ef60e0bead2c0b19a778d8b76c274b4` and its authorship. Validation on Windows x86-64 / Rust 1.98.1: - An external Cargo harness imports the actual `shader_cache.rs` and depends on the actual `victory-shader` and `victory-pipeline` crates, with no behavior stubs or GPU host feature. **All seven cache-module tests pass**, including mutation of every byte, truncation, appended data, correctly checksummed malformed fields, and on-disk corruption followed by retranslation and a cache hit. - `cargo test -p victory-pipeline --locked`: **eight tests pass**. - Strict all-target harness Clippy, changed-file rustfmt, and repository asset policy (`191 files ok`) pass. - `cargo test -p victory-gpu --lib shader_cache:: --locked -- --test-threads=1` builds the full GPU test binary successfully, but that binary exits before starting the test harness with `STATUS_ACCESS_VIOLATION` (`0xc0000005`) on this machine. Full GPU-binary test execution is therefore still unverified here; the isolated module results above are reported separately. - The contributor also recorded Linux validation and a Windows-target compile check in the linked follow-up PR. Those are their results, separate from the native Windows checks above. All new fixtures are synthetic. No game files, game assets, retail checks, or gameplay execution used. No dependencies or CI files changed. The follow-up's existing Windows CI approval was granted; this description does not claim that run has passed. AI-assisted: GPT-6.1 Sol; community contribution retains its own attribution.
Dukestar69 commented 2026-11-26 08:11:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T08:11:46Z.

Review: APPROVED


Verified against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1: 4/4 passed (including truncated refusal retranslation and same-length blake3 corruption rejection).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Adding a length prefix and blake3 digest under the VSF2 refusal tag cleanly turns torn/corrupted cached refusal entries into cache misses.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6070498508 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3098#pullrequestreview-6070498508). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T08:11:46Z. **Review:** APPROVED --- Verified against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1`: 4/4 passed (including truncated refusal retranslation and same-length blake3 corruption rejection). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Adding a length prefix and blake3 digest under the `VSF2` refusal tag cleanly turns torn/corrupted cached refusal entries into cache misses. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 08:39:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:39:58Z.

Review: COMMENTED


Verified locally on Windows 11:

  • cargo test -p victory-gpu --lib -- shader_cache:: (default and --all-features): 4/4 passed
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --all-features): clean
  • cargo xtask policy: 191 files ok

The VSF2 encode/decode implementation itself is clean and memory-safe: Reader::take checks bounds via split_at_checked before allocating, and truncation at any offset, trailing garbage (!r.0.is_empty()), same-length bit flips, invalid UTF-8, and legacy VSHE files are all rejected cleanly into cache misses.

Two small observations for maintainers / polish:

  1. Scope / symmetry: victory-pipeline's Cache::get_or_convert already publishes entries via write-temp-then-rename (though without sync_all, so power-loss truncation or external disk corruption is still possible). Adding a 32-byte BLAKE3 digest only to refusal entries while VSH1 shader entries rely solely on length framing + r.0.is_empty() is slightly asymmetric — if maintainers prefer minimal format complexity, framing refusals with r.list()? + r.0.is_empty() already matches VSH1's truncation guarantees, whereas keeping the BLAKE3 check here is cheap and harmless.
  2. Minor nits: in decode, binding let tag = r.take(4)?; once avoids resetting r = Reader(bytes) and checking the prefix twice; and entries_round_trip_and_reject_damage could also cover trailing extra bytes on a VSF2 entry (matching the VSH1 trailing-byte test right above it).
<!-- greyfinch-sync:Marvisak/VIctory:review:6070844379 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3098#pullrequestreview-6070844379). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:39:58Z. **Review:** COMMENTED --- Verified locally on Windows 11: - `cargo test -p victory-gpu --lib -- shader_cache::` (default and `--all-features`): 4/4 passed - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`): clean - `cargo xtask policy`: 191 files ok The `VSF2` encode/decode implementation itself is clean and memory-safe: `Reader::take` checks bounds via `split_at_checked` before allocating, and truncation at any offset, trailing garbage (`!r.0.is_empty()`), same-length bit flips, invalid UTF-8, and legacy `VSHE` files are all rejected cleanly into cache misses. Two small observations for maintainers / polish: 1. **Scope / symmetry**: `victory-pipeline`'s `Cache::get_or_convert` already publishes entries via write-temp-then-rename (though without `sync_all`, so power-loss truncation or external disk corruption is still possible). Adding a 32-byte BLAKE3 digest only to refusal entries while `VSH1` shader entries rely solely on length framing + `r.0.is_empty()` is slightly asymmetric — if maintainers prefer minimal format complexity, framing refusals with `r.list()?` + `r.0.is_empty()` already matches `VSH1`'s truncation guarantees, whereas keeping the BLAKE3 check here is cheap and harmless. 2. **Minor nits**: in `decode`, binding `let tag = r.take(4)?;` once avoids resetting `r = Reader(bytes)` and checking the prefix twice; and `entries_round_trip_and_reject_damage` could also cover trailing extra bytes on a `VSF2` entry (matching the `VSH1` trailing-byte test right above it).
Marvisak commented 2026-11-26 09:06:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:24:27Z.


Automated triage for the maintainers.

Needs work. The encoding change in crates/victory-gpu/src/shader_cache.rs (encode/decode, VSHE to VSF2 with a length and a BLAKE3 digest) reads correctly, and CI passes. The problem is that it guards against something that does not happen through this code, and it does nothing for the entries that matter more:

  • Entries go through victory_pipeline::Cache, which writes to a temp file and renames it (crates/victory-pipeline/src/cache.rs, "Write-then-rename so readers never see partial output"). A torn refusal entry can only come from damage outside VIctory.
  • When that does happen, the cost today is a shortened reason string in a log. The container is still refused, which is the right outcome for it.
  • Successful translations (VSH1) get no digest. A damaged VSH1 entry that still parses would hand the GPU wrong DXIL, which is a far worse result than a short refusal reason.

What would change the verdict: a real path where a refusal entry ends up truncated (a run log or a reproduction), or an integrity check that covers every entry. That check probably belongs in victory_pipeline::Cache rather than in one entry kind. The translate closure reformat in host_shader is unrelated to the fix and can be dropped.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186555967 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3098#issuecomment-7186555967). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T08:24:27Z. --- <!-- victory-triage v1 head=edd8d503ed32e94667ad340c12a29555f0be932a verdict=needs-work at=2026-11-26T08:18:11Z --> Automated triage for the maintainers. **Needs work.** The encoding change in `crates/victory-gpu/src/shader_cache.rs` (`encode`/`decode`, `VSHE` to `VSF2` with a length and a BLAKE3 digest) reads correctly, and CI passes. The problem is that it guards against something that does not happen through this code, and it does nothing for the entries that matter more: - Entries go through `victory_pipeline::Cache`, which writes to a temp file and renames it (`crates/victory-pipeline/src/cache.rs`, "Write-then-rename so readers never see partial output"). A torn refusal entry can only come from damage outside VIctory. - When that does happen, the cost today is a shortened reason string in a log. The container is still refused, which is the right outcome for it. - Successful translations (`VSH1`) get no digest. A damaged `VSH1` entry that still parses would hand the GPU wrong DXIL, which is a far worse result than a short refusal reason. What would change the verdict: a real path where a refusal entry ends up truncated (a run log or a reproduction), or an integrity check that covers every entry. That check probably belongs in `victory_pipeline::Cache` rather than in one entry kind. The `translate` closure reformat in `host_shader` is unrelated to the fix and can be dropped. --- _Generated by [Claude Code](https://claude.ai/code)_
XeNS1 commented 2026-11-26 09:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by XeNS1 on 2026-11-26T08:53:04Z.


I prepared the requested all-entry integrity follow-up against the existing author branch: https://github.com/yefan911/VIctory/pull/1 (commit 71de96199e). Both original yefan911 commits are preserved; no competing upstream PR was opened.

The new tests reproduce a successful cache entry returning changed DXIL as a hit, and a single-byte edit changing PS to VS. A common trailing BLAKE3 digest now covers the whole serialized success/refusal entry before any fields are decoded. Three new tests cover all single-byte edits, truncation/append, correctly checksummed malformed fields, and actual disk corruption followed by a miss/retranslation/hit. No claim of a naturally torn atomic write; this addresses the broader integrity option in triage.

Native Linux: the harness imports the actual shader_cache.rs and actual victory-shader/victory-pipeline crates, with no behavior stubs. All 7 module tests and 7 pipeline tests pass; strict all-target Clippy, rustfmt and asset policy pass. The two new success regressions fail on edd8d503 (4 pass / 2 fail), and pass with the follow-up (7 / 0). No game files or GPU execution used. The new encoding changes the existing source fingerprint, so old translated entries are rebuilt once.

The author's CI run requires their approval. cargo check --locked --offline --target x86_64-pc-windows-msvc -p victory-gpu --lib --tests --all-features --features blake3/pure also passes with Rust 1.100; its only two warnings are unchanged Atomic::fetch_update deprecations in object.rs. This is a Windows-target compile check; Windows execution and GPU validation are not claimed.

AI-assisted: OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7187138327 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3098#issuecomment-7187138327). Originally posted by [XeNS1](https://github.com/XeNS1) on 2026-11-26T08:53:04Z. --- I prepared the requested all-entry integrity follow-up against the existing author branch: https://github.com/yefan911/VIctory/pull/1 (commit 71de96199ef60e0bead2c0b19a778d8b76c274b4). Both original yefan911 commits are preserved; no competing upstream PR was opened. The new tests reproduce a successful cache entry returning changed DXIL as a hit, and a single-byte edit changing PS to VS. A common trailing BLAKE3 digest now covers the whole serialized success/refusal entry before any fields are decoded. Three new tests cover all single-byte edits, truncation/append, correctly checksummed malformed fields, and actual disk corruption followed by a miss/retranslation/hit. No claim of a naturally torn atomic write; this addresses the broader integrity option in triage. Native Linux: the harness imports the actual shader_cache.rs and actual victory-shader/victory-pipeline crates, with no behavior stubs. All 7 module tests and 7 pipeline tests pass; strict all-target Clippy, rustfmt and asset policy pass. The two new success regressions fail on edd8d503 (4 pass / 2 fail), and pass with the follow-up (7 / 0). No game files or GPU execution used. The new encoding changes the existing source fingerprint, so old translated entries are rebuilt once. The author's CI run requires their approval. `cargo check --locked --offline --target x86_64-pc-windows-msvc -p victory-gpu --lib --tests --all-features --features blake3/pure` also passes with Rust 1.100; its only two warnings are unchanged Atomic::fetch_update deprecations in object.rs. This is a Windows-target compile check; Windows execution and GPU validation are not claimed. AI-assisted: OpenAI Codex.
futurepro62 commented 2026-11-27 06:37:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T06:37:52Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, since none of them names a GPU run. Tested exact head 359fab3 (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: 869 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: a_digest_does_not_make_malformed_fields_valid, every_translation_byte_is_checked, damaged_success_is_retranslated.
  • --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:7211702436 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3098#issuecomment-7211702436). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-27T06:37:52Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, since none of them names a GPU run. Tested exact head `359fab3` (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`: **869 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `a_digest_does_not_make_malformed_fields_valid`, `every_translation_byte_is_checked`, `damaged_success_is_retranslated`. - `--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.
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/3098:upstream-pr/3098'
git switch 'upstream-pr/3098'

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