fix(loader): prepare no longer overflows on RVAs past 4 GiB #91

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

@⁠Caasares on GitHub · 2026-11-27 17:53 UTC · original
Caasares:fix/pe-prepare-rva-overflow → main · +101 −6 · 1 files · 1 commits · closed without merging

Bug

victory_loader::prepare adds header-supplied RVAs with plain +, in two places:

  1. dir64_relocations: each IMAGE_REL_BASED_DIR64 target is page + offset, where page is the relocation block's page RVA and offset is 12 bits.
  2. prepare: the TLS callback field's RVA is tls.directory_rva + 24.

Impact

For a malformed image either sum can pass u32::MAX, and ImageInfo::parse accepts both inputs:

  • a relocation page RVA such as 0xFFFFF001 with offset 0xFFF (target 0x1_0000_0000);
  • a TLS directory at 0xFFFFFFE8 in a section that ends at the top of the 32-bit RVA space.

A debug build panics (attempt to add with overflow). A release build wraps silently, so the relocation target becomes a wrong RVA. A wrapped TLS field RVA could also match an unrelated relocation entry and clear it.

Valid images are not affected.

Root cause

Unchecked u32 addition on values read from the image header and relocation table.

Fix

  • dir64_relocations skips an entry whose target does not fit in a u32 (checked_add), instead of wrapping.
  • The TLS callback field's RVA is computed with checked_add. If it does not fit, no relocation can point at the field, so nothing is cleared.

Changes are confined to crates/victory-loader/src/prepare.rs.

How it was tested

  • Two regression tests in prepare.rs, each built from a crafted image:

    • relocation_targets_past_the_top_of_the_rva_space_are_skipped
    • tls_directory_at_the_top_of_the_rva_space_is_prepared

    Both fail on main with attempt to add with overflow and pass with this change.

  • cargo test -p victory-loader --locked: all tests pass (45 library tests and both integration tests).

  • cargo test --workspace --locked --no-fail-fast: the only failures are two victory-gpu indirect tests, which already fail on main and are not touched here.

  • cargo clippy -p victory-loader --locked -- -D warnings and the same with --all-features: clean.

  • --all-targets reports four transmute lint errors in write_sites.rs that already exist on main. This change adds none.

  • rustfmt --check is clean for prepare.rs. The repository's apps/ already has formatting differences on main, which this change does not touch.

  • A mutation run of about 60,000 corrupted images through ImageInfo::parse and prepare found no other panic.

**@⁠Caasares** on GitHub · 2026-11-27 17:53 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/91) `Caasares:fix/pe-prepare-rva-overflow` → `main` · +101 −6 · 1 files · 1 commits · closed without merging ## Bug `victory_loader::prepare` adds header-supplied RVAs with plain `+`, in two places: 1. `dir64_relocations`: each `IMAGE_REL_BASED_DIR64` target is `page + offset`, where `page` is the relocation block's page RVA and `offset` is 12 bits. 2. `prepare`: the TLS callback field's RVA is `tls.directory_rva + 24`. ## Impact For a malformed image either sum can pass `u32::MAX`, and `ImageInfo::parse` accepts both inputs: - a relocation page RVA such as `0xFFFFF001` with offset `0xFFF` (target `0x1_0000_0000`); - a TLS directory at `0xFFFFFFE8` in a section that ends at the top of the 32-bit RVA space. A debug build panics (`attempt to add with overflow`). A release build wraps silently, so the relocation target becomes a wrong RVA. A wrapped TLS field RVA could also match an unrelated relocation entry and clear it. Valid images are not affected. ## Root cause Unchecked `u32` addition on values read from the image header and relocation table. ## Fix - `dir64_relocations` skips an entry whose target does not fit in a `u32` (`checked_add`), instead of wrapping. - The TLS callback field's RVA is computed with `checked_add`. If it does not fit, no relocation can point at the field, so nothing is cleared. Changes are confined to `crates/victory-loader/src/prepare.rs`. ## How it was tested - Two regression tests in `prepare.rs`, each built from a crafted image: - `relocation_targets_past_the_top_of_the_rva_space_are_skipped` - `tls_directory_at_the_top_of_the_rva_space_is_prepared` Both fail on `main` with `attempt to add with overflow` and pass with this change. - `cargo test -p victory-loader --locked`: all tests pass (45 library tests and both integration tests). - `cargo test --workspace --locked --no-fail-fast`: the only failures are two `victory-gpu` `indirect` tests, which already fail on `main` and are not touched here. - `cargo clippy -p victory-loader --locked -- -D warnings` and the same with `--all-features`: clean. - `--all-targets` reports four `transmute` lint errors in `write_sites.rs` that already exist on `main`. This change adds none. - `rustfmt --check` is clean for `prepare.rs`. The repository's `apps/` already has formatting differences on `main`, which this change does not touch. - A mutation run of about 60,000 corrupted images through `ImageInfo::parse` and `prepare` found no other panic.
prepare() added a relocation's page RVA to its in-page offset, and the
TLS callback field's RVA to the directory's RVA, with plain `+`. In a
malformed image either sum can pass u32::MAX: a debug build panics, and
a release build wraps to a wrong RVA. Skip a relocation target that has
no RVA, and treat a TLS field with no RVA as having no relocation to
clear.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 17:59:59 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-28 00:40 UTC · original

Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #91 at head 95b990d39a07685b77a5f89492bb705d62d23bbc, merge base 29d8dbf7d9892ceb8bec378a9dbc3c4f2931b745.
  • cargo test --locked -p victory-loader --lib -- prepare::tests::relocation_targets_past_the_top_of_the_rva_space_are_skipped --exact --test-threads=1 --quiet → 1 passed, 0 failed, 44 filtered, exit 0.
  • git grep -F for the test name on the merge base returned no hits (test is new on this PR); git diff --check 29d8dbf7 HEAD clean (1 file, +101/-6).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally (no clippy component on this toolchain).
  • GPU/driver: N/A (CPU-only loader test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-28 00:40 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/91#issuecomment-7231103771) Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #91 at head `95b990d39a07685b77a5f89492bb705d62d23bbc`, merge base `29d8dbf7d9892ceb8bec378a9dbc3c4f2931b745`. - `cargo test --locked -p victory-loader --lib -- prepare::tests::relocation_targets_past_the_top_of_the_rva_space_are_skipped --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 44 filtered, exit 0. - `git grep -F` for the test name on the merge base returned no hits (test is new on this PR); `git diff --check 29d8dbf7 HEAD` clean (1 file, +101/-6). - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed; full workspace suite and clippy were not run locally (no clippy component on this toolchain). - GPU/driver: N/A (CPU-only loader test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
github-bot closed this pull request 2026-11-28 02:54:20 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-28 02:49 UTC · original

Merged into main (8fc2254) and shipped in v2026.11.27.10. The commit keeps you as its author, so it counts toward the contributors list. GitHub shows this as closed rather than merged only because the commits were applied on top of the newest main (new commit IDs). Thank you!

**@⁠trustno1-coder** on GitHub · 2026-11-28 02:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/91#issuecomment-7232613625) Merged into main (8fc2254) and shipped in [v2026.11.27.10](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/tag/v2026.11.27.10). The commit keeps you as its author, so it counts toward the contributors list. GitHub shows this as closed rather than merged only because the commits were applied on top of the newest main (new commit IDs). Thank you!

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/trustno1-coder--VIctory-NVIDIA!91
No description provided.