Skip to content

Loader: skip DIR64 relocation addresses that overflow u32 - #3243

Open
andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/2411-dir64-page-overflow
Open

andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/2411-dir64-page-overflow

Conversation

@andrewpozdnakov7-jpg

@andrewpozdnakov7-jpg andrewpozdnakov7-jpg commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

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.

@cloph-dsp

Copy link
Copy Markdown

Independent local verification (Windows, Rust 1.100.0/MSVC, synthetic inputs only, no game data).

  • PR head: 2b898b6; merge base with origin/main: 63bcca4.
  • Command: cargo test --locked -p victory-loader --lib -- prepare::tests::relocation_addresses_past_u32_are_skipped --exact --test-threads=1 --quiet
  • Result: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 35 filtered out, exit 0.
  • git diff --check 63bcca4 HEAD: exit 0, clean.
  • Negative control: git grep -n relocation_addresses_past_u32_are_skipped 63bcca4 -> 0 hits; the test is new on this PR.

Caveat: this run exercises the extracted reloc_address helper, not dir64_relocations end-to-end; no malformed-BASERELOC fixture was replayed here.

AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only loader test). No game data, assets or DRM involved.

@pushkarreddyy

pushkarreddyy commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

@cloph-dsp Thank you for the independent local verification on 2b898b6!

@Marvisak Please review and merge this PR when convenient. Testers on untested setups are welcome to test.

AI-assisted: yes (Gemini 4 Neon)

Airamek pushed a commit to Airamek/VIctory that referenced this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loader: guard dir64_relocations against BASERELOC size and page+offset overflow

4 participants