Game: scan past false-positive MAGIC streams and optimize shaderpack::find #2534
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2534
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2534/head"
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?
@reeledMarek on GitHub · 2026-11-25 15:23 UTC · original
reeledMarek:fix/game-shaderpack-find-scan-and-perf→main· +87 −28 · 1 files · 1 commits · closed without mergingProblem
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.@Marvisak on GitHub · 2026-11-25 15:54 UTC · original
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
@rezioliver-collab on GitHub · 2026-11-25 19:39 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 22:10 UTC · original
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