Game: use checked length arithmetic and avoid discarded Vec allocations in sgd5 #2577

Closed
github-bot wants to merge 1 commit from github-bot/gh-2577 into main AGit
Owner

@⁠reeledMarek on GitHub · 2026-11-25 16:08 UTC · original
reeledMarek:fix/game-sgd5-checked-math-and-allocs → main · +46 −18 · 1 files · 1 commits · closed without merging

Summary

Fixes unchecked arithmetic and wasted allocations in victory-game/src/sgd5.rs:

  1. Replaces unchecked length/offset arithmetic with checked_mul / checked_add so malformed SGD5 payloads return a clean parse error instead of overflowing or panicking.
  2. Removes discarded intermediate Vec allocations during SGD5 entry decoding, parsing directly from borrowed slices (as_chunks::<4>()).

Testing

  • cargo test -p victory-game --locked (16/16 passed)
  • cargo clippy -p victory-game --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings (clean)
  • cargo test -p xtask --locked (6/6 passed)
  • Synthetic unit tests only; no game files used.
**@⁠reeledMarek** on GitHub · 2026-11-25 16:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2577) `reeledMarek:fix/game-sgd5-checked-math-and-allocs` → `main` · +46 −18 · 1 files · 1 commits · closed without merging ### Summary Fixes unchecked arithmetic and wasted allocations in `victory-game/src/sgd5.rs`: 1. Replaces unchecked length/offset arithmetic with `checked_mul` / `checked_add` so malformed SGD5 payloads return a clean parse error instead of overflowing or panicking. 2. Removes discarded intermediate `Vec` allocations during SGD5 entry decoding, parsing directly from borrowed slices (`as_chunks::<4>()`). ### Testing - `cargo test -p victory-game --locked` (16/16 passed) - `cargo clippy -p victory-game --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` (clean) - `cargo test -p xtask --locked` (6/6 passed) - Synthetic unit tests only; no game files used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:09:38 +00:00
github-bot closed this pull request 2026-11-26 06:30:41 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:17 UTC · original

Automated triage for the maintainers.

Proposed close: guards for cases that cannot happen. VIctory builds only for x86_64-pc-windows-msvc (rust-toolchain.toml). In sgd5::record and sgd5::effect, every term added is either a u32 widened to a 64-bit usize or the length of a slice already read from the file. at + 12, at + n and the loaded sum cannot overflow there. On main an oversized length already makes file.get(..) / Cursor::bytes return None. The new test record_rejects_overflowing_length passes on main unchanged for that reason, so it does not show a bug. What remains is skip_items in place of two discarded small Vecs in an offline parser, which does not justify the change by itself.

This PR will be closed in 48 hours unless the author pushes a change (for example a case that panics or misparses on main) or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2577#issuecomment-7176181905) <!-- victory-triage v1 head=1e418d296b8b6800fa55f7d67aba0632714d8fc8 verdict=proposed-close at=2026-11-25T22:17:30Z --> Automated triage for the maintainers. **Proposed close: guards for cases that cannot happen.** VIctory builds only for `x86_64-pc-windows-msvc` (`rust-toolchain.toml`). In `sgd5::record` and `sgd5::effect`, every term added is either a `u32` widened to a 64-bit `usize` or the length of a slice already read from the file. `at + 12`, `at + n` and the `loaded` sum cannot overflow there. On `main` an oversized length already makes `file.get(..)` / `Cursor::bytes` return `None`. The new test `record_rejects_overflowing_length` passes on `main` unchanged for that reason, so it does not show a bug. What remains is `skip_items` in place of two discarded small `Vec`s in an offline parser, which does not justify the change by itself. This PR will be closed in 48 hours unless the author pushes a change (for example a case that panics or misparses on `main`) or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-26 05:43 UTC · original

Closing per triage and @⁠lcg007xd-c's review: on x86-64 Windows the usize additions in sgd5 cannot wrap and file.get/Cursor::bytes already reject oversized lengths, so the remaining skip_items refactor alone does not justify a PR. Thanks for the thorough check!

**@⁠reeledMarek** on GitHub · 2026-11-26 05:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2577#issuecomment-7183748539) Closing per triage and @⁠lcg007xd-c's review: on x86-64 Windows the `usize` additions in `sgd5` cannot wrap and `file.get`/`Cursor::bytes` already reject oversized lengths, so the remaining `skip_items` refactor alone does not justify a PR. Thanks for the thorough check!

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!2577
No description provided.