[pr-fix][startup][shaders] Guard shader cache retention against overflow #260
Loading…
Reference in a new issue
No description provided.
Delete branch "qnjk/Darner:fix-shader-cache-retention-overflow"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Tested with offline shader warm-up on a local Xbox build. Gameplay and FPS were not measured.
Contributor role (optional)
What it changes
An excessively large positive
DARNER_SHADER_CACHE_DAYScan 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
f3840d73d3504c30218debfbc8795b9225447317plus 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.darner translate <synthetic-file> --warm all --jobs 1exited 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.darner translate <title-exe> --warm all --jobs 1translated 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.Checklist
main.docs/asset-policy.md.Checked for overlap
Independent Windows build, gate, and code-read review of
7bc78e68d(based onmainf3840d73d). Not run in-game.Environment
x86_64-pc-windows-msvc), MSVC 19.44.35230.Measured results
cargo clippy --workspace --all-targets --locked -- -D warnings): PASScargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASScargo xtask policy: PASS (asset policy: 555 files ok)cargo test --locked -p darner-gpu --lib shader_cache: PASS (14 passed; 0 failedin 4.21 s, including newcache_retention_ignores_invalid_or_overflowing_days)Code-read audit
cache_max_age(crates/darner-gpu/src/shader_cache.rs:66-69) parses viaNonZeroU64and multiplies viadays.checked_mul(86_400).map(Duration::from_secs), fixing both the debug multiplication panic and silentu64wrap-around in release builds (whereu64::MAX / 86_400 + 1wrapped to55,424s).Cache::prune(max_age)(crates/darner-pipeline/src/cache.rs:162-199): it only comparesage >= max_age/age > max_ageand performs noSystemTimearithmetic withmax_age, somax_days * 86_400cannot overflow downstream.max_days,max_days + 1,"0","-1", and"invalid". (Touchesshader_cache.rsalongside #253 and #292 on disjoint hunks.)Verdict: PASS.
AI-assisted: yes (Gemini 4 Neon).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.