loader: stop clzero loop emulation before address wraparound #3256

Open
github-bot wants to merge 1 commit from github-bot/gh-3256 into main AGit
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 14:46 UTC · original
cloph-dsp:fix/clzero-wraparound → main · +22 −3 · 1 files · 1 commits · open

Depends on: #1633 (claim CLZERO-WRAPAROUND; earlier PR #2555 closed unmerged).

The emulated clzero loops advanced their line pointer with wrapping_add(0x40). If a loop's limit was near u64::MAX, the pointer wrapped to a small address and the emulator kept zeroing lines instead of ending the pass. A small advance_line helper now uses checked_add and both loops stop when the next line would wrap.

Test: crash::tests::clzero_loop_advance_stops_before_u64_wraparound checks the valid boundary (u64::MAX - 0x40 → u64::MAX) and that u64::MAX - 0x3f and u64::MAX are rejected, without touching invalid memory.

Validation (Windows, Rust 1.100.0/MSVC, worktree-local CARGO_TARGET_DIR):

  • cargo test --locked -p victory-loader --lib -- clzero — 8 passed, 0 failed (existing loop tests unchanged).
  • git diff --check — clean.
  • Negative control: the new test name is absent from origin/main.

AI-assisted (Hy4 flash). Synthetic inputs only; no game assets, extracted shaders, logs or DRM material were used or uploaded.

**@⁠cloph-dsp** on GitHub · 2026-11-26 14:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/3256) `cloph-dsp:fix/clzero-wraparound` → `main` · +22 −3 · 1 files · 1 commits · open Depends on: #1633 (claim `CLZERO-WRAPAROUND`; earlier PR #2555 closed unmerged). The emulated `clzero` loops advanced their line pointer with `wrapping_add(0x40)`. If a loop's limit was near `u64::MAX`, the pointer wrapped to a small address and the emulator kept zeroing lines instead of ending the pass. A small `advance_line` helper now uses `checked_add` and both loops stop when the next line would wrap. Test: `crash::tests::clzero_loop_advance_stops_before_u64_wraparound` checks the valid boundary (`u64::MAX - 0x40` → `u64::MAX`) and that `u64::MAX - 0x3f` and `u64::MAX` are rejected, without touching invalid memory. Validation (Windows, Rust 1.100.0/MSVC, worktree-local `CARGO_TARGET_DIR`): - `cargo test --locked -p victory-loader --lib -- clzero` — 8 passed, 0 failed (existing loop tests unchanged). - `git diff --check` — clean. - Negative control: the new test name is absent from `origin/main`. AI-assisted (Hy4 flash). Synthetic inputs only; no game assets, extracted shaders, logs or DRM material were used or uploaded.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:48:00 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 15:05 UTC · original · reviewed

Two things:

  • Same case as #2555, which triage proposed to close: the cursor is a user-mode address the title zeroes, so it can't come within 64 bytes of u64::MAX (reeledMarek closed it on that basis). Unless something has changed since, this guards an unreachable case; worth answering that triage note in the description.
  • The doc comments got swapped: advance_line is inserted between clzero's doc comment (/// # Safety …) and unsafe fn clzero, so the Safety section now documents advance_line and clzero has none. Moving the helper above that comment block fixes it.
**@⁠AurumCarlos** on GitHub · 2026-11-26 15:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/3256#pullrequestreview-6076434001) · **reviewed** Two things: - **Same case as #2555, which triage proposed to close**: the cursor is a user-mode address the title zeroes, so it can't come within 64 bytes of `u64::MAX` (reeledMarek closed it on that basis). Unless something has changed since, this guards an unreachable case; worth answering that triage note in the description. - **The doc comments got swapped**: `advance_line` is inserted between `clzero`'s doc comment (`/// # Safety …`) and `unsafe fn clzero`, so the Safety section now documents `advance_line` and `clzero` has none. Moving the helper above that comment block fixes it.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 15:31 UTC · original · approved these changes

Reviewed the diff and verified locally on Windows 11 x64:

  • Using advance_line (checked_add(0x40)) in both clzero loop emulation paths cleanly stops before u64 address wraparound instead of wrapping to low memory.
  • cargo test -p victory-loader --lib crash:: -- --test-threads=1: 25 passed, 0 failed (including clzero_loop_advance_stops_before_u64_wraparound).
  • cargo clippy -p victory-loader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 15:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/3256#pullrequestreview-6076796874) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64: - Using `advance_line` (`checked_add(0x40)`) in both `clzero` loop emulation paths cleanly stops before `u64` address wraparound instead of wrapping to low memory. - `cargo test -p victory-loader --lib crash:: -- --test-threads=1`: 25 passed, 0 failed (including `clzero_loop_advance_stops_before_u64_wraparound`). - `cargo clippy -p victory-loader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3256/head:github-bot/gh-3256'
git switch 'github-bot/gh-3256'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3256'
git switch 'github-bot/gh-3256'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3256'
git switch 'github-bot/gh-3256'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3256'
git switch 'main'
git merge --squash 'github-bot/gh-3256'
git switch 'main'
git merge --ff-only 'github-bot/gh-3256'
git switch 'main'
git merge 'github-bot/gh-3256'
git push origin 'main'
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!3256
No description provided.