Loader: guard dir64_relocations against BASERELOC size and page+offset overflow #2411
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#2411
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@pushkarreddyy on GitHub · 2026-11-25 13:07 UTC · original
Summary
In
crates/victory-loader/src/prepare.rs(dir64_relocations), parsing theBASERELOCdata directory computes:end = start as usize + size as usizewithout clamping tobytes.len()or using saturating/checked addition;at + block > endwithoutchecked_add;page + u32::from(e & 0xFFF)withoutchecked_add, which panics in debug builds onu32overflow for malformed relocation pages.Expected
Clamp
endtobytes.len()with saturating arithmetic and usechecked_addfor block bounds andpage + offset.Claiming this issue and opening a PR with unit tests shortly.
@Marvisak on GitHub · 2026-11-25 18:49 UTC · original
Automated triage for the maintainers.
Partly confirmed in
dir64_relocationsincrates/victory-loader/src/prepare.rs.page + u32::from(e & 0xFFF)is plainu32addition. A malformed block whose page RVA is nearu32::MAXpanics there in debug builds and wraps in release builds.The other two points do not lead to a failure on the 64-bit hosts this runs on:
startandsizeareu32values widened tousize, so neitherstart + sizenorat + blockcan overflow.endpast the file is harmless, because every read goes throughlayout::read_u32orbytes.get. Those returnNone, and the loop then stops.Clamping
endis still reasonable as hardening. Open PR #2418 addresses all three.Generated by Claude Code
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 14:17 UTC · original
Took the narrow part of this, as the triage above scoped it: only
page + u32::from(e & 0xFFF)can actually fail on the 64-bit hosts VIctory builds for.start + sizeandat + blockare ausizeplus au32and cannot overflow there, and reads past the end already stop throughlayout::read_u32andbytes.get.Commit 2ad0aa0 on
fix/2411-dir64-page-overflow:A malformed entry is skipped one at a time, so a bad page base does not throw away the well-formed entries after it.
endis also clamped tobytes.len()withsaturating_add, which changes nothing for valid files — the directory is inside the file — but keeps the bound honest.Test
relocation_addresses_past_u32_are_skippedcovers0x1000 + 0x0A, the last address0xFFFF_FF0F + 0xF, the overflowing0xFFFF_FFF0 + 0x10, and the type/offset split0xA000 -> 0x2000.On this machine, compiled at
63bcca4:cargo test -p victory-loadercargo clippy -p victory-loader --all-targets -- -D warningscargo xtask policyThe one 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 and not this change.@pushkarreddyy #2418 guards the same three places, but two of them cannot fail here; if the maintainers prefer that one, this can be dropped — the
reloc_addresspart is the only behavioural difference.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 14:26 UTC · original
Opened PR #3243 for the narrow part:
eloc_address with checked_add, a malformed entry skipped on its own, and end clamped to ytes.len(). CI check passed (2m42s), the PR is clean on main. Details and the local results are in the PR body; the coordination claim is in #1633.