Game: check record bounds and offset arithmetic in SGD5 parsing #1435
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1436"
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 fuzeofficlal on 2026-11-24T17:58:20Z.
Fixes #905.
Summary
sgd5::recordandsgd5::name_beforewithchecked_add,checked_sub, and.get(...)bounds checks so truncated or malformedSGD5streams returnNoneinstead of panicking.Verification
rejects_boundary_and_malformed_recordscovering short prefixes (at < 6), truncated headers/payloads, mismatched lengths,u32::MAX/usize::MAXoffsets, and malformed name prefixes.cargo test --workspace,cargo clippy --workspace --all-targets --all-features, andcargo xtask policy: passed.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:25:06Z.
Review: APPROVED
SGD5 record parsing is now panic-free at the boundaries: every offset goes through
checked_add/checked_sub,file.getreplaces direct indexing (including the NUL byte and name-length checks inname_before), and truncated/oversized/mismatched records returnNone. The newrejects_boundary_and_malformed_recordstest covers marker-at-start, near-start padding, truncation,n < 12, mismatchedn, oversizedunpacked_size,u32::MAXsizes and extreme synthetic offsets — verified running on macOS arm64 (cargo test -p victory-game --locked: 3 passed, 0 failed, +1).Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:28:14Z.
Automated triage for the maintainers.
Proposed close: guards for cases that cannot occur. In
crates/victory-game/src/sgd5.rsonmain,record()has a single caller,records(), which passesatfrommemmem::find_iter(file, &MARKER). Soat + 4 <= file.len(), andat + 4,at + 8,at + 12andat + n(withnfrom au32) cannot overflowusize. The existingat.checked_sub(6)?already returns beforefile[nul]andfile[at - 5]could go out of range.file.get(at + 12..at + n)already rejects a truncated payload.name_beforeis only called withnul < at <= file.len(), so its indices are in range too. Everyrecords(..)assertion in the new test also holds onmain. The calls that differ (record(&MARKER, usize::MAX),name_before(&[0], 5)) use arguments no caller can pass. The same change was closed before as #1153.A malformed input that makes
mainpanic throughrecords()would change this verdict.CI: passing (
check).This pull request will be closed in 48 hours unless the author pushes a change or a maintainer removes the
triage: proposed closelabel.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T10:16:54Z.
Agreed with the triage analysis —
records()boundsatviamemmem::find_iterand.get(...)on 64-bitusize, so the internal helper edge cases cannot be reached onmain. Closing to keep the review queue focused.Pull request closed