Game: check record bounds and offset arithmetic in SGD5 parsing #1436

Closed
github-bot wants to merge 1 commit from gh-pr/1436/head into gh-pr/1436/base
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 17:58 UTC · original
fuzeofficlal:fix/game-sgd5-bounds-905 → main · +70 −9 · 1 files · 1 commits · closed without merging

Fixes #905.

Summary

  • Replace unchecked slice indexing and offset arithmetic in sgd5::record and sgd5::name_before with checked_add, checked_sub, and .get(...) bounds checks so truncated or malformed SGD5 streams return None instead of panicking.

Verification

  • Added rejects_boundary_and_malformed_records covering short prefixes (at < 6), truncated headers/payloads, mismatched lengths, u32::MAX / usize::MAX offsets, and malformed name prefixes.
  • cargo test --workspace, cargo clippy --workspace --all-targets --all-features, and cargo xtask policy: passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-24 17:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1436) `fuzeofficlal:fix/game-sgd5-bounds-905` → `main` · +70 −9 · 1 files · 1 commits · closed without merging Fixes #905. ### Summary - Replace unchecked slice indexing and offset arithmetic in `sgd5::record` and `sgd5::name_before` with `checked_add`, `checked_sub`, and `.get(...)` bounds checks so truncated or malformed `SGD5` streams return `None` instead of panicking. ### Verification - Added `rejects_boundary_and_malformed_records` covering short prefixes (`at < 6`), truncated headers/payloads, mismatched lengths, `u32::MAX` / `usize::MAX` offsets, and malformed name prefixes. - `cargo test --workspace`, `cargo clippy --workspace --all-targets --all-features`, and `cargo xtask policy`: passed.
Use checked offset arithmetic and bounds-checked slice indexing in record and name_before so malformed or truncated SGD5 streams return None instead of overflowing or panicking.

Closes #905
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:31:41 +00:00
github-bot closed this pull request 2026-11-26 04:31:41 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:28 UTC · original · edited 2026-11-25 06:30 UTC

Automated triage for the maintainers.

Proposed close: guards for cases that cannot occur. In crates/victory-game/src/sgd5.rs on main, record() has a single caller, records(), which passes at from memmem::find_iter(file, &MARKER). So at + 4 <= file.len(), and at + 4, at + 8, at + 12 and at + n (with n from a u32) cannot overflow usize. The existing at.checked_sub(6)? already returns before file[nul] and file[at - 5] could go out of range. file.get(at + 12..at + n) already rejects a truncated payload. name_before is only called with nul < at <= file.len(), so its indices are in range too. Every records(..) assertion in the new test also holds on main. 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 main panic through records() 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 close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1436#issuecomment-7149582056) · edited 2026-11-25 06:30 UTC <!-- victory-triage v1 head=4d9539023eafb82fcb708a719f62eb09edfb1a07 verdict=proposed-close at=2026-11-25T06:30:22Z --> Automated triage for the maintainers. **Proposed close: guards for cases that cannot occur.** In `crates/victory-game/src/sgd5.rs` on `main`, `record()` has a single caller, `records()`, which passes `at` from `memmem::find_iter(file, &MARKER)`. So `at + 4 <= file.len()`, and `at + 4`, `at + 8`, `at + 12` and `at + n` (with `n` from a `u32`) cannot overflow `usize`. The existing `at.checked_sub(6)?` already returns before `file[nul]` and `file[at - 5]` could go out of range. `file.get(at + 12..at + n)` already rejects a truncated payload. `name_before` is only called with `nul < at <= file.len()`, so its indices are in range too. Every `records(..)` assertion in the new test also holds on `main`. 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 `main` panic through `records()` 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 close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 10:16 UTC · original

Agreed with the triage analysis — records() bounds at via memmem::find_iter and .get(...) on 64-bit usize, so the internal helper edge cases cannot be reached on main. Closing to keep the review queue focused.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 10:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1436#issuecomment-7159480045) Agreed with the triage analysis — `records()` bounds `at` via `memmem::find_iter` and `.get(...)` on 64-bit `usize`, so the internal helper edge cases cannot be reached on `main`. Closing to keep the review queue focused.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1436
No description provided.