[pr-fix][startup][shaders] Guard shader cache retention against overflow #260

Open
qnjk wants to merge 1 commit from qnjk/Darner:fix-shader-cache-retention-overflow into main
First-time contributor

Tested with offline shader warm-up on a local Xbox build. Gameplay and FPS were not measured.

Contributor role (optional)

  • Fluxer ID:

What it changes

An excessively large positive DARNER_SHADER_CACHE_DAYS can overflow when converted to seconds. A debug build with the original retention code panicked during cache setup. Use checked multiplication and skip pruning when the setting cannot be represented. The boundary test covers normal values, the largest representable day count, the first overflowing value, zero, negative and invalid input.

How it was tested

  • Tested revision: f3840d73d3504c30218debfbc8795b9225447317 plus this patch, Rust 1.98.1 on Windows.
  • cargo test --locked -p darner-gpu --lib shader_cache::tests: 14 passed.
  • cargo test --locked -p darner-pipeline: 15 passed.
  • cargo clippy --locked -p darner-gpu --all-targets -- -D warnings: passed.
  • cargo xtask policy: 555 files passed.
  • cargo build --locked -p darner: passed.
  • CLI smoke test: darner translate <synthetic-file> --warm all --jobs 1 exited successfully with 30 days and with the largest unsigned 64-bit day count. The prior debug build used for #253, which has the original retention code, exited with a multiplication overflow for the latter.
  • Local build: with the overflowing setting, darner translate <title-exe> --warm all --jobs 1 translated 15 shaders into an isolated cache, then served all 15 from that cache on a second run. The executable's SHA-256 matched before and after.
  • Changes a default: no. Pruning is opt-in.
  • A/B: the CLI smoke test compares the original and patched handling of the overflowing setting.
  • Gates run: none of the three workspace-wide gates. Targeted checks are listed above.
  • Gameplay: offline shader warm-up only.
  • Shader wave sizes tested: no dedicated wave-size comparison.
  • Hardware dependence: checked during cache setup on Windows.
  • Coverage gaps: gameplay, FPS and other platforms.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Checked the affected cache setup through offline warm-up with a local build.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #32, #33, #38, #39, #40, #41, #43, #44, #45, #46, #47, #48, #49, #96, #142 and #253 share the file. #142 changes prune-thread bookkeeping. #253 changes cache-key construction.
  • Replaces or overlaps: none found for the overflowing day-to-seconds conversion.
Tested with offline shader warm-up on a local Xbox build. Gameplay and FPS were not measured. ## Contributor role (optional) - Fluxer ID: ## What it changes An excessively large positive `DARNER_SHADER_CACHE_DAYS` can overflow when converted to seconds. A debug build with the original retention code panicked during cache setup. Use checked multiplication and skip pruning when the setting cannot be represented. The boundary test covers normal values, the largest representable day count, the first overflowing value, zero, negative and invalid input. ## How it was tested - Tested revision: `f3840d73d3504c30218debfbc8795b9225447317` plus this patch, Rust 1.98.1 on Windows. - `cargo test --locked -p darner-gpu --lib shader_cache::tests`: 14 passed. - `cargo test --locked -p darner-pipeline`: 15 passed. - `cargo clippy --locked -p darner-gpu --all-targets -- -D warnings`: passed. - `cargo xtask policy`: 555 files passed. - `cargo build --locked -p darner`: passed. - CLI smoke test: `darner translate <synthetic-file> --warm all --jobs 1` exited successfully with 30 days and with the largest unsigned 64-bit day count. The prior debug build used for #253, which has the original retention code, exited with a multiplication overflow for the latter. - Local build: with the overflowing setting, `darner translate <title-exe> --warm all --jobs 1` translated 15 shaders into an isolated cache, then served all 15 from that cache on a second run. The executable's SHA-256 matched before and after. - Changes a default: no. Pruning is opt-in. - A/B: the CLI smoke test compares the original and patched handling of the overflowing setting. - Gates run: none of the three workspace-wide gates. Targeted checks are listed above. - Gameplay: offline shader warm-up only. - Shader wave sizes tested: no dedicated wave-size comparison. - Hardware dependence: checked during cache setup on Windows. - Coverage gaps: gameplay, FPS and other platforms. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). - Checked the affected cache setup through offline warm-up with a local build. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #32, #33, #38, #39, #40, #41, #43, #44, #45, #46, #47, #48, #49, #96, #142 and #253 share the file. #142 changes prune-thread bookkeeping. #253 changes cache-key construction. - Replaces or overlaps: none found for the overflowing day-to-seconds conversion.
First-time contributor

Independent Windows build, gate, and code-read review of 7bc78e68d (based on main f3840d73d). Not run in-game.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS
  • cargo xtask policy: PASS (asset policy: 555 files ok)
  • cargo test --locked -p darner-gpu --lib shader_cache: PASS (14 passed; 0 failed in 4.21 s, including new cache_retention_ignores_invalid_or_overflowing_days)

Code-read audit

  • cache_max_age (crates/darner-gpu/src/shader_cache.rs:66-69) parses via NonZeroU64 and multiplies via days.checked_mul(86_400).map(Duration::from_secs), fixing both the debug multiplication panic and silent u64 wrap-around in release builds (where u64::MAX / 86_400 + 1 wrapped to 55,424 s).
  • Checked Cache::prune(max_age) (crates/darner-pipeline/src/cache.rs:162-199): it only compares age >= max_age / age > max_age and performs no SystemTime arithmetic with max_age, so max_days * 86_400 cannot overflow downstream.
  • Boundary test covers normal, max_days, max_days + 1, "0", "-1", and "invalid". (Touches shader_cache.rs alongside #253 and #292 on disjoint hunks.)

Verdict: PASS.

AI-assisted: yes (Gemini 4 Neon).

Independent Windows build, gate, and code-read review of `7bc78e68d` (based on `main` `f3840d73d`). Not run in-game. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS** - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS** - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`) - `cargo test --locked -p darner-gpu --lib shader_cache`: **PASS** (`14 passed; 0 failed` in 4.21 s, including new `cache_retention_ignores_invalid_or_overflowing_days`) ### Code-read audit - `cache_max_age` (`crates/darner-gpu/src/shader_cache.rs:66-69`) parses via `NonZeroU64` and multiplies via `days.checked_mul(86_400).map(Duration::from_secs)`, fixing both the debug multiplication panic and silent `u64` wrap-around in release builds (where `u64::MAX / 86_400 + 1` wrapped to `55,424` s). - Checked `Cache::prune(max_age)` (`crates/darner-pipeline/src/cache.rs:162-199`): it only compares `age >= max_age` / `age > max_age` and performs no `SystemTime` arithmetic with `max_age`, so `max_days * 86_400` cannot overflow downstream. - Boundary test covers normal, `max_days`, `max_days + 1`, `"0"`, `"-1"`, and `"invalid"`. (Touches `shader_cache.rs` alongside #253 and #292 on disjoint hunks.) **Verdict:** PASS. AI-assisted: yes (Gemini 4 Neon).
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 'fix-shader-cache-retention-overflow:qnjk-fix-shader-cache-retention-overflow'
git switch 'qnjk-fix-shader-cache-retention-overflow'

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 'qnjk-fix-shader-cache-retention-overflow'
git switch 'qnjk-fix-shader-cache-retention-overflow'
git rebase 'main'
git switch 'main'
git merge --ff-only 'qnjk-fix-shader-cache-retention-overflow'
git switch 'qnjk-fix-shader-cache-retention-overflow'
git rebase 'main'
git switch 'main'
git merge --no-ff 'qnjk-fix-shader-cache-retention-overflow'
git switch 'main'
git merge --squash 'qnjk-fix-shader-cache-retention-overflow'
git switch 'main'
git merge --ff-only 'qnjk-fix-shader-cache-retention-overflow'
git switch 'main'
git merge 'qnjk-fix-shader-cache-retention-overflow'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!260
No description provided.