GPU: reject truncated or corrupted shader refusal entries #3098

Open
github-bot wants to merge 2 commits from github-bot/gh-3098 into main AGit
Owner

@⁠yefan911 on GitHub · 2026-11-26 07:52 UTC · original
yefan911:fix/shader-refusal-cache-integrity → main · +50 −9 · 1 files · 2 commits · open

Follow-up to #1094. That change caches deterministic shader refusals, but the VSHE entry contains only the marker and UTF-8 reason. A truncated entry can therefore be accepted as a cache hit with an empty or shortened reason.

This stores the reason length and a BLAKE3 digest in a versioned VSF2 refusal entry. Decode requires the exact payload length, valid UTF-8, and matching digest; damaged entries become misses and are translated again. The cache key includes this source file’s encoding, so entries using the old refusal format are invalidated.

Adds regression coverage for truncation and same-length corruption, plus the existing refusal-hit path. No game data used.

Validation: Windows-target cargo check --locked --target x86_64-pc-windows-msvc -p victory-gpu --lib --tests --features blake3/pure passed; rustfmt --edition 2024 --check crates/victory-gpu/src/shader_cache.rs and git diff --check passed. The tests compile, but cannot be executed in this Linux environment.

**@⁠yefan911** on GitHub · 2026-11-26 07:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/3098) `yefan911:fix/shader-refusal-cache-integrity` → `main` · +50 −9 · 1 files · 2 commits · open Follow-up to #1094. That change caches deterministic shader refusals, but the `VSHE` entry contains only the marker and UTF-8 reason. A truncated entry can therefore be accepted as a cache hit with an empty or shortened reason. This stores the reason length and a BLAKE3 digest in a versioned `VSF2` refusal entry. Decode requires the exact payload length, valid UTF-8, and matching digest; damaged entries become misses and are translated again. The cache key includes this source file’s encoding, so entries using the old refusal format are invalidated. Adds regression coverage for truncation and same-length corruption, plus the existing refusal-hit path. No game data used. Validation: Windows-target `cargo check --locked --target x86_64-pc-windows-msvc -p victory-gpu --lib --tests --features blake3/pure` passed; `rustfmt --edition 2024 --check crates/victory-gpu/src/shader_cache.rs` and `git diff --check` passed. The tests compile, but cannot be executed in this Linux environment.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:06:54 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 08:11 UTC · original · approved these changes

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 08:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/3098#pullrequestreview-6070498508) · **approved these changes** 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:24 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 08:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3098#issuecomment-7186555967) <!-- 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)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 08:39 UTC · original · reviewed

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).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/3098#pullrequestreview-6070844379) · **reviewed** 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).
Author
Owner

@⁠XeNS1 on GitHub · 2026-11-26 08:53 UTC · original

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.

**@⁠XeNS1** on GitHub · 2026-11-26 08:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/3098#issuecomment-7187138327) 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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3098/head:github-bot/gh-3098'
git switch 'github-bot/gh-3098'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3098'
git switch 'github-bot/gh-3098'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3098'
git switch 'github-bot/gh-3098'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3098'
git switch 'main'
git merge --squash 'github-bot/gh-3098'
git switch 'main'
git merge --ff-only 'github-bot/gh-3098'
git switch 'main'
git merge 'github-bot/gh-3098'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3098
No description provided.