Loader: a relocation past the top of the address space is not wrapped #344
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!344
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/344/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@SkippySteve on GitHub · 2026-11-24 02:26 UTC · original
SkippySteve/loader-reloc-overflow→main· +65 −9 · 1 files · 1 commits · closed without mergingprepare()walks the base relocation table to find theDIR64entry that patches the TLS callback field, so it can neutralise it. The walk added each entry's page offset to its block's page RVA unchecked:A damaged block whose page RVA sits near
u32::MAX(e.g.0xFFFF_FFF0with an entry at+0x10) panics withattempt to add with overflowin debug builds. In release it wraps to a low RVA. If that RVA happens to equal the TLS callback field,prepare()zeroes an unrelated relocation entry.Change (
crates/victory-loader/src/prepare.rsonly)dir64_entries(bytes, start, end)over plain bytes. It useschecked_addand leaves out targets that don't fit in an RVA.dir64_relocationsstill finds the directory and delegates to it.start.saturating_add(size).directory_rva + 12) useschecked_add. On overflow it returnsPrepareError::Patchinstead of wrapping.Behaviour for well-formed images doesn't change.
Tests
Two new unit tests build relocation blocks in memory and need no PE, so they run on every host:
dir64_entries_walk_blocks_and_skip_other_types: walks several blocks, skips ABSOLUTE and HIGHLOW entries, and stops at a block that claims more than the directory holds.dir64_entries_drop_targets_past_the_top_of_the_address_space: entries that fit up to0xFFFF_FFFFare kept, entries that overflow are dropped, and anendpast the buffer stops at the bytes that are there.On the old code the second test fails with
attempt to add with overflow.On Linux,
cargo test -p victory-loader --lib dir64passes 2/2, andcargo clippy -p victory-loader --all-targets -- -D warningsis clean.rustfmt --checkon the file is clean too. The three existingpreparetests readcurrent_exe()as a PE, so they already fail on Linux onmain(#235 gates them). This PR doesn't change them.@CesarLopesO on GitHub · 2026-11-24 02:30 UTC · original
Independent validation — Debian 13 (Trixie)
I tested the current PR head
dfefeddlocally on Debian 13.Results
cargo test --locked -p victory-loader --lib dir64— 2 passed, 0 failed (3 filtered out).cargo clippy --locked -p victory-loader --all-targets -- -D warnings— passed with no warnings.rustfmt --edition 2024 --check crates/victory-loader/src/prepare.rs— passed.cargo xtask policy— passed (151 files).The two new
dir64_entriestests pass on Linux, including the overflow-boundary regression case. I did not run the full workspace test suite as part of this validation.No game files or game data were used.
Thanks for the fix!
@SkippySteve on GitHub · 2026-11-24 02:32 UTC · original
Superseded by #287, which now carries this commit (relocation overflow in prepare) alongside the other loader/PE tests.
Pull request closed