Game: scan past false-positive MAGIC streams and optimize shaderpack::find #2532
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2534"
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?
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:23:46Z.
Problem
shaderpack::findused.find_map()to lock onto the first 16-byte-aligned zlib stream starting withMAGIC(b"PS\0\x09"). If an earlier stream in an archive falsely started with those 4 bytes, assembly failed and returnedNonewithout scanning the rest of the archive.findconstructed a fresh ~10.5 KiBDecompressorOxide::new()and inflated + heap-allocated the full 64 KiB output of every zlib stream in multi-hundred-MiB archives just to inspect the first 4 bytes.size()used unchecked multiplication/addition on untrusted header fields.Fix
Box<DecompressorOxide>(reset with.init()) and probe only the first 4 output bytes before inflating a full stream.MAGICstreams continue scanning instead of aborting.to_vec()allocations, reservetotalwhen known, and use checked arithmetic insize().Testing
skips_false_positive_magic_stream_before_real_packincrates/victory-game/src/shaderpack.rs.cargo test -p victory-game --locked, Windows cross-clippy (-D warnings), andcargo test -p xtask --locked.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:54:39Z.
Automated triage for the maintainers.
Recommended for a look.
shaderpack::find(crates/victory-game/src/shaderpack.rs) now keeps scanning when a stream that starts with the pack magic does not assemble into a whole pack (main returnedNoneat the first such stream), reuses one decompressor and probes only the first 4 output bytes before inflating a full stream, and uses checked arithmetic insize(). I checked the loop against the old logic (a truncated pack still yieldsNone, so the existing test holds) and the new test covers the false-positive case. Small nits: thepack.reserveline is not rustfmt-formatted and itsfile.len() * 64cap is an arbitrary bound. CI (clippy + tests on Windows): passing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by rezioliver-collab on 2026-11-25T19:39:02Z.
On an M1 Mac (macOS 14.7, Rust 1.98.1, release builds), median
shaderpack::findtime fell from 28.65 ms onmain(13f91ca) to 3.27 ms on this PR (b0d98d23). The median paired speedup was 8.75×.We timed only the in-memory search on the same 34.43 MiB synthetic archive. It contained 1,024 unrelated zlib streams before the target pack. We alternated which build ran first across 20 pairs. Each build did one warm-up and three timed searches per pair (60 timed searches per build).
The PR was faster in all 20 pairs. After every search, including warm-ups, we compared the returned bytes with the original 147,666-byte pack. Both builds matched it byte for byte every time.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:10:46Z.
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because none of the three problems occurs with the title's archive. Before the pack, 2,172 aligned offsets pass the zlib-header test and none of them inflates, so no chunk is inflated or allocated early and there is no false-positive magic stream.
size()multiplies u32 fields in a 64-bitusize, which cannot overflow. What remains is saving about 4,205 copies of 64 KiB once per pre-build, for a more complex loop.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed