PE: reject out-of-range export addresses in parse_exports (fixes #2412) #2418
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2420"
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:11:15Z.
Fixes #2412.
Root Cause
In
crates/victory-pe/src/image.rs(parse_exports), export RVAs were computed fromobject'sReadTarget::Address { address }usingaddress.wrapping_sub(image_base) as u32. If a malformed PE export address is belowimage_baseoraddress - image_base > u32::MAX,wrapping_subandas u32silently wrap/truncate to an invalid 32-bit RVA instead of returningPeError::Malformed.Implementation Details
export_rva(address: u64, image_base: u64) -> Result<u32, PeError>usingchecked_sub(image_base)andu32::try_from, returningPeError::Malformedon underflow oru32overflow.parse_exportsto callexport_rva(address, image_base)?.Verification
export_rva_rejects_underflow_and_u32_overflowunit test incrates/victory-pe/src/image.rsverifying valid RVAs, underflow belowimage_base, and overflow pastu32::MAX.check(workspace build, clippy-D warnings, and tests) is green.Scope & Limitations
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:19:27Z.
Review: APPROVED
Verified against
origin/main(940d32f):parse_exports(#2412) is clean and well-tested.cargo test -p victory-pe: 37/37 passed (includingexport_rva_rejects_underflow_and_u32_overflow).cargo clippy -p victory-pe --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:25:26Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-pe --lockedon macOS arm64 — 33 passed, and the 4 failures are exactly the known pre-existing image::tests macOS-environment ones (identical on main). Approving — out-of-range export addresses rejected in parse_exports.Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-25T13:36:22Z.
Hi @Marvisak — this PR resolves #2412 (rejecting out-of-range export addresses in
parse_exportswithPeError::Malformedinstead of wrapping/truncating), with unit tests and CI (check) passing. Ready for review and merge whenever convenient!Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T13:53:19Z.
Reviewed:
wrapping_sub→checked_sub+u32::try_fromis the right fix — a PE64 export RVA must be a u32 above the image base. Test covers both reject directions and the happy path.Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-25T14:19:03Z.
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)
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:29:05Z.
Automated triage for the maintainers.
Proposed close. The error this adds cannot happen. In
image.rsparse_exports, the address comes fromobject's generic export iterator, which (as the existing comment says) builds it as the image base plus the 32-bit RVA from the export table. So onmain,address.wrapping_sub(image_base) as u32always gives back the exact RVA; the value cannot be below the image base or more thanu32::MAXabove it except through a wrap that the current code already undoes correctly, and the newexport_rvawould turn that case into an error. The unit test only calls the helper with values the iterator cannot produce.This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-26T15:19:04Z.
Closing this PR after reviewing the triage verification on
main:parse_exports,object's generic export iterator constructs addresses asimage_base + rva, soaddress.wrapping_sub(image_base) as u32onmainalready recovers the exact 32-bit RVA (including wrapped sums).mainalready handles correctly.Thank you for the verification.
AI-assisted: yes (Gemini 4 Neon)
Pull request closed