Loader: skip DIR64 relocation addresses that overflow u32 #3243

Open
github-bot wants to merge 2 commits from github-bot/gh-3243 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 14:22 UTC · original
andrewpozdnakov7-jpg:fix/2411-dir64-page-overflow → main · +30 −3 · 1 files · 2 commits · open

A malformed BASERELOC block puts the page RVA near u32::MAX; page + u32::from(e & 0xFFF) in dir64_relocations then panics in debug builds and wraps in release ones, returning a relocation address that was never in the image.

reloc_address now uses checked_add, and an entry that does not fit is skipped on its own, so a bad page base does not throw away the well-formed entries after it. end is clamped to bytes.len() with saturating_add; valid files are unchanged, since the directory is inside the file.

  • relocation_addresses_past_u32_are_skipped covers 0x1000 + 0x0A, the last address 0xFFFF_FFF0 + 0xF, the overflowing 0xFFFF_FFF0 + 0x10, and the type/offset split 0xA000 -> 0x2000.
  • cargo test -p victory-loader: 35 passed, 1 failed. The failure is prepare::tests::windows_assigns_static_tls_to_a_prepared_dll ("the test binary uses static TLS"); it fails identically with this patch stashed, so it is local to this machine.
  • cargo clippy -p victory-loader --all-targets -- -D warnings: clean. cargo xtask policy: 192 files ok.

The other two points in #2411 cannot fail on the 64-bit hosts VIctory builds for: start + size and at + block are a usize plus a u32, and reads past the end already stop through layout::read_u32 and bytes.get. #2418 guards those as well, with a proposed close triage for that reason; the reloc_address change is the behavioural difference. The issue's proposed arithmetic came from @⁠pushkarreddyy.

Fixes #2411.

Coordination

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 14:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/3243) `andrewpozdnakov7-jpg:fix/2411-dir64-page-overflow` → `main` · +30 −3 · 1 files · 2 commits · open A malformed `BASERELOC` block puts the page RVA near `u32::MAX`; `page + u32::from(e & 0xFFF)` in `dir64_relocations` then panics in debug builds and wraps in release ones, returning a relocation address that was never in the image. `reloc_address` now uses `checked_add`, and an entry that does not fit is skipped on its own, so a bad page base does not throw away the well-formed entries after it. `end` is clamped to `bytes.len()` with `saturating_add`; valid files are unchanged, since the directory is inside the file. - `relocation_addresses_past_u32_are_skipped` covers `0x1000 + 0x0A`, the last address `0xFFFF_FFF0 + 0xF`, the overflowing `0xFFFF_FFF0 + 0x10`, and the type/offset split `0xA000 -> 0x2000`. - `cargo test -p victory-loader`: 35 passed, 1 failed. The failure is `prepare::tests::windows_assigns_static_tls_to_a_prepared_dll` ("the test binary uses static TLS"); it fails identically with this patch stashed, so it is local to this machine. - `cargo clippy -p victory-loader --all-targets -- -D warnings`: clean. `cargo xtask policy`: 192 files ok. The other two points in #2411 cannot fail on the 64-bit hosts VIctory builds for: `start + size` and `at + block` are a `usize` plus a `u32`, and reads past the end already stop through `layout::read_u32` and `bytes.get`. #2418 guards those as well, with a `proposed close` triage for that reason; the `reloc_address` change is the behavioural difference. The issue's proposed arithmetic came from @⁠pushkarreddyy. Fixes #2411. [Coordination](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:27:16 +00:00
Author
Owner

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

Reviewed the diff and verified locally on Windows 11 x64:

  • Using checked_add in
    eloc_address and clamping end with saturating_add(...).min(bytes.len()) cleanly prevents debug overflow panics and release wraparound on malformed BASERELOC blocks.
  • Minor non-blocking formatting nit in prepare.rs: n dir64_relocations(...) { const DIR64: u16 = 10; is on one line and the doc comment for dir64_relocations was left above
    eloc_address.
  • cargo test -p victory-loader -- --test-threads=1: 36 unit + 4 integration tests passed, 0 failed (including
    elocation_addresses_past_u32_are_skipped).
  • 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 14:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/3243#pullrequestreview-6075858988) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64: - Using checked_add in eloc_address and clamping end with saturating_add(...).min(bytes.len()) cleanly prevents debug overflow panics and release wraparound on malformed BASERELOC blocks. - Minor non-blocking formatting nit in prepare.rs: n dir64_relocations(...) { const DIR64: u16 = 10; is on one line and the doc comment for dir64_relocations was left above eloc_address. - cargo test -p victory-loader -- --test-threads=1: 36 unit + 4 integration tests passed, 0 failed (including elocation_addresses_past_u32_are_skipped). - 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).
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 15:39 UTC · original

Thanks for catching this. 2b898b6 moves the iterator's doc comment back to dir64_relocations and puts const DIR64 on its own line. The patch changes comments and whitespace. The loader builds with all features.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 15:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/3243#issuecomment-7196581422) Thanks for catching this. [`2b898b6`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/2b898b60fd4abb45c0048232f3421a7ee2d4f0aa) moves the iterator's doc comment back to `dir64_relocations` and puts `const DIR64` on its own line. The patch changes comments and whitespace. The loader builds with all features.
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/3243/head:github-bot/gh-3243'
git switch 'github-bot/gh-3243'

Merge

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