Use checked addition in console_insn and write_sites bounds checks #435

Closed
github-bot wants to merge 660 commits from github-bot/gh-435 into main AGit
Owner

@⁠ahmetbagci8 on GitHub · 2026-11-29 10:48 UTC · original
ahmetbagci8:fix/loader-checked-bounds-overflow → main · +60053 −5432 · 206 files · 660 commits · closed without merging

Summary

Two unchecked usize additions in victory-loader can overflow on edge-case inputs:

  1. crates/victory-loader/src/console_insn.rs (readable / writable): called from the extern "system" VEH (emulate), where a clzero with Rax in 0xFFFF_FFFF_FFFF_FFC0..=u64::MAX overflows va + 64 (panicking inside the VEH in debug builds, or wrapping in release).
  2. crates/victory-loader/src/write_sites.rs (apply): an entry in VICTORY_WRITE_SITES with a hex offset in usize::MAX - 15..=usize::MAX overflows offset + 16 (panicking in debug, or wrapping past the > size check and reading out of bounds in release).

Changes

  • Use checked_add in console_insn::readable, console_insn::writable, and write_sites::apply.
  • Add unit tests overflowing_ranges_do_not_panic_in_veh and overflowing_offsets_are_ignored.

Tested

  • cargo test -p victory-loader: 73 passed; 0 failed; 0 ignored
  • cargo clippy -p victory-loader --tests: clean (0 warnings)
**@⁠ahmetbagci8** on GitHub · 2026-11-29 10:48 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/435) `ahmetbagci8:fix/loader-checked-bounds-overflow` → `main` · +60053 −5432 · 206 files · 660 commits · closed without merging ### Summary Two unchecked `usize` additions in `victory-loader` can overflow on edge-case inputs: 1. `crates/victory-loader/src/console_insn.rs` (`readable` / `writable`): called from the `extern "system"` VEH (`emulate`), where a `clzero` with `Rax` in `0xFFFF_FFFF_FFFF_FFC0..=u64::MAX` overflows `va + 64` (panicking inside the VEH in debug builds, or wrapping in release). 2. `crates/victory-loader/src/write_sites.rs` (`apply`): an entry in `VICTORY_WRITE_SITES` with a hex offset in `usize::MAX - 15..=usize::MAX` overflows `offset + 16` (panicking in debug, or wrapping past the `> size` check and reading out of bounds in release). ### Changes - Use `checked_add` in `console_insn::readable`, `console_insn::writable`, and `write_sites::apply`. - Add unit tests `overflowing_ranges_do_not_panic_in_veh` and `overflowing_offsets_are_ignored`. ### Tested - `cargo test -p victory-loader`: `73 passed; 0 failed; 0 ignored` - `cargo clippy -p victory-loader --tests`: clean (0 warnings)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 10:50:13 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-11-29 11:20 UTC · original · reviewed

Ran this on Windows. cargo test -p victory-loader gives 73 passed (70 lib + 3 in the other targets), both new tests included, and cargo clippy -p victory-loader --all-targets -D warnings is clean.

The checks look right. In apply, base + offset after the new check can't wrap any more since offset + 16 <= size. In readable, the region end is now checked too, which the old code also added unchecked. The new VEH test goes through the whole emulate path with Rax = u64::MAX and returns 0 instead of panicking in debug.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-11-29 11:20 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/435#pullrequestreview-6102640033) · **reviewed** Ran this on Windows. `cargo test -p victory-loader` gives 73 passed (70 lib + 3 in the other targets), both new tests included, and `cargo clippy -p victory-loader --all-targets -D warnings` is clean. The checks look right. In `apply`, `base + offset` after the new check can't wrap any more since `offset + 16 <= size`. In `readable`, the region end is now checked too, which the old code also added unchecked. The new VEH test goes through the whole `emulate` path with `Rax = u64::MAX` and returns 0 instead of panicking in debug. AI-assisted: yes
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 11:35 UTC · original

Thanks for the native Windows verification, especially the full VEH path with Rax at u64::MAX. The overflow cases need to fail safely rather than panic or access an invalid range. I'll keep this separate from unrelated loader changes.

**@⁠TaynanGT** on GitHub · 2026-11-29 11:35 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/435#issuecomment-7255214628) Thanks for the native Windows verification, especially the full VEH path with Rax at u64::MAX. The overflow cases need to fail safely rather than panic or access an invalid range. I'll keep this separate from unrelated loader changes.
github-bot closed this pull request 2026-11-30 17:08:42 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-30 17:07 UTC · original

main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

**@⁠TaynanGT** on GitHub · 2026-11-30 17:07 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/435#issuecomment-7285751042) `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.