Loader: guard dir64_relocations against BASERELOC size and page+offset overflow #2409
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?
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-25T13:07:28Z.
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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:49:25Z.
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
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T14:17:25Z.
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.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T14:26:53Z.
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.