game: check record bounds and offset arithmetic in SGD5 parsing (fix on a fork) #905
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#905
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@DaniiL35 on GitHub · 2026-11-24 13:51 UTC · original
Pull requests are currently restricted to collaborators (#717), so I am sharing this bug report and verified fix from a clean fork branch off
main(ffe310e).• Branch: https://github.com/DaniiL35/VIctory/tree/fix/sgd5-checked-record-bounds
• Commit:
7a5db56(based onmainffe310e,crates/victory-game/src/sgd5.rs+53/-9)• Compare: https://github.com/Marvisak/VIctory/compare/main...DaniiL35:VIctory:fix/sgd5-checked-record-bounds
Problem
In
crates/victory-game/src/sgd5.rs,record()extracts packed shader container records from memory/archive slices by searching for the marker0x000D_DCE7. When verifying sizes and extracting the compressed stream:at + 12..at + n) and header offsets (at + 8,at + 4) used uncheckedusizeaddition, which can panic on integer overflow with hostile/corrupt inputs near memory boundaries.file[at - 5],file[nul]) relied on unchecked indexing rather than slice bounds checks. Ifatwas located near boundary conditions (such as invalid offsets whereat < 6), slice index panics or underflows could occur.name_beforeused unchecked indexingfile[l]when scanning backwards for the name length byte.Fix
checked_addandchecked_subthroughoutrecord():start = at.checked_add(12)?andend = at.checked_add(n)?with validation thatstart <= end.u32_atcomputeso.checked_add(4)?safely..get()(file.get(nul) == Some(&0),file.get(at.checked_sub(5)?)?).name_beforewith.get()on both length extraction and substring slice.Tests Added
Added
rejects_boundary_and_malformed_recordsincrates/victory-game/src/sgd5.rscovering:at < 6), assertingNonewithout panic.n < 12, assertingNone.u32_at(at + 4) != n), assertingNone.unpacked_size > MAX_UNPACKED(64 MiB), assertingNone.nexceeds available buffer length, assertingNone.Verification & Policy Compliance
cargo xtask policy(text-only, <512 KiB).main(ffe310e).AI-assisted with Antigravity.
@DaniiL35 on GitHub · 2026-11-24 16:17 UTC · original
PR opened directly: #1153
@Marvisak on GitHub · 2026-11-25 06:53 UTC · original
Automated triage for the maintainers.
Reading
recordincrates/victory-game/src/sgd5.rsonmain, the panics described cannot happen:at.checked_sub(4)?andnul = at.checked_sub(6)?returnNonefor a marker within six bytes of the start, sofile[nul]andfile[at - 5]are always in bounds (both belowat, which is inside the file);u32_atand the payload usefile.get(..), which returnsNonefor a truncated or reversed range; andat + ncannot overflow for an offset inside a slice.name_beforeonly indexes belownul. So the change would be hardening, not a fix. Pull request #1153 that carried it was closed without being merged; if you want it considered as hardening, a new pull request is open to everyone.Generated by Claude Code