Loader: guard dir64_relocations against BASERELOC size and page+offset overflow (fixes #2411) #2418
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!2418
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2418"
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:10 UTC · original
pushkarreddyy:fix/loader-dir64-reloc-bounds→main· +36 −7 · 1 files · 1 commits · closed without mergingFixes #2411.
Root Cause
In
crates/victory-loader/src/prepare.rs(dir64_relocations), parsing theBASERELOCdata directory used unchecked arithmetic:end = start as usize + size as usizedid not saturate or clamp tobytes.len().at + block > endcould overflow on malformed block sizes.page + u32::from(e & 0xFFF)could overflow and panic in debug builds whenpage > u32::MAX - 0xFFF.Implementation Details
endto(start as usize).saturating_add(size as usize).min(bytes.len()).block < 8 || at + block > endwithat.checked_add(block).filter(|&next| block >= 8 && next <= end).page + u32::from(e & 0xFFF)withpage.checked_add(u32::from(e & 0xFFF)).Verification
dir64_relocations_clamps_oversized_directory_and_overflowing_pagesunit test incrates/victory-loader/src/prepare.rscovering oversizedu32::MAXdirectory sizes andu32::MAXpage base arithmetic.check(workspace build, clippy-D warnings, and tests) is green.Scope & Limitations
IMAGE_REL_BASED_DIR64relocation entries are unchanged; malformed overflowing entries are safely ignored.@pushkarreddyy on GitHub · 2026-11-25 13:36 UTC · original
Hi @Marvisak — this PR resolves #2411 (clamping
BASERELOCdirectory bounds and guardingat + blockandpage + offsetagainst overflow indir64_relocations), with unit tests and CI (check) passing. Ready for review and merge whenever convenient!@kotekompotek on GitHub · 2026-11-25 13:53 UTC · original
Reviewed:
endis now clamped tobytes.len(), the block bound is achecked_add, andpage + offsetno longer overflows u32 — all three panic paths from #2411 covered. The test mutates a copy of its own exe (no fixture), which fits the asset policy.@pushkarreddyy on GitHub · 2026-11-25 14:18 UTC · original
Thank you @kotekompotek for the review! Testers on untested Windows 10/11 and Wine/Proton configurations are welcome to verify.
AI-assisted: yes (Gemini 4 Neon)
@Marvisak on GitHub · 2026-11-25 15:29 UTC · original
Automated triage for the maintainers.
Proposed close. This adds guards for cases that cannot fail in
prepare.rsdir64_relocations:start + sizeandat + blockare a usize plus a u32 and cannot overflow on the 64-bit targets VIctory builds for;layout::read_u32andbytes.getreturnNoneand the loop breaks;page + (e & 0xFFF)can only overflow for a page RVA above 0xFFFFF000 in a corrupt executable, and the result is only compared with the TLS callback field's RVA, so a wrapped value simply never matches in release builds.The test's first call makes no assertion. An input that reaches a real failure here would change the verdict.
This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.
Generated by Claude Code
@DenRakEiw on GitHub · 2026-11-25 13:19 UTC · original · approved these changes
Verified against
origin/main(940d32f):dir64_relocationsagainst oversizedBASERELOCdirectories andpage + offsetoverflows (#2411) is clean and well-tested.cargo test -p victory-loader: 39/39 passed (35 unit includingdir64_relocations_clamps_oversized_directory_and_overflowing_pages+ 4 integration tests).cargo clippy -p victory-loader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 13:25 UTC · original · approved these changes
Tested locally: merged into main
940d32f69b,cargo test -p victory-loader --lockedon macOS arm64. All 4 failures — including this PR's new dir64_relocations_clamps_oversized_directory_and_overflowing_pages — are environmental: prepare::tests parse the host's own Mach-O binary as PE ("Unknown file magic"), same as the 3 pre-existing ones on main. They can't pass off Windows by construction; #2334's #[cfg(windows)] gating already handles this class (this new test should get the same gate when it rebases past #2334). The BASERELOC guard logic itself is sound. Approving.@pushkarreddyy on GitHub · 2026-11-26 15:19 UTC · original
Closing this PR after reviewing the triage verification on
main:usize + u32(start + sizeandat + block) cannot overflow, andlayout::read_u32/bytes.getalready stop cleanly on EOF.page + (e & 0xFFF)can only wrap for corrupt executables with page RVAs above0xFFFFF000, which will not match a valid TLS callback RVA.Thank you for the audit.
AI-assisted: yes (Gemini 4 Neon)
Pull request closed