PE: reject out-of-range export addresses in parse_exports instead of wrapping #2412

Open
opened 2026-11-26 05:04:59 +00:00 by github-bot · 1 comment
Owner

@⁠pushkarreddyy on GitHub · 2026-11-25 13:07 UTC · original

Summary

In crates/victory-pe/src/image.rs (parse_exports), export RVAs are reconstructed from object's ReadTarget::Address { address } using:

(Some(address.wrapping_sub(image_base) as u32), None)

If a malformed PE export address is below image_base or address - image_base > u32::MAX, wrapping_sub + as u32 silently wraps/truncates into a bogus 32-bit RVA instead of returning PeError::Malformed.

Expected

Use checked_sub(image_base) and u32::try_from, returning PeError::Malformed on out-of-range export addresses.

Claiming this issue and opening a PR with unit tests shortly.

**@⁠pushkarreddyy** on GitHub · 2026-11-25 13:07 UTC · [original](https://github.com/Marvisak/VIctory/issues/2412) ### Summary In `crates/victory-pe/src/image.rs` (`parse_exports`), export RVAs are reconstructed from `object`'s `ReadTarget::Address { address }` using: ```rust (Some(address.wrapping_sub(image_base) as u32), None) ``` If a malformed PE export address is below `image_base` or `address - image_base > u32::MAX`, `wrapping_sub` + `as u32` silently wraps/truncates into a bogus 32-bit RVA instead of returning `PeError::Malformed`. ### Expected Use `checked_sub(image_base)` and `u32::try_from`, returning `PeError::Malformed` on out-of-range export addresses. *Claiming this issue and opening a PR with unit tests shortly.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:04:59 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:45 UTC · original

Automated triage for the maintainers.

Read against main (da82e44): in crates/victory-pe/src/image.rs, parse_exports, the address object (0.41) hands back is the image base plus the 32-bit RVA stored in the export address table. address.wrapping_sub(image_base) as u32 undoes exactly that sum, so it always recovers the original table value; an export address below the image base or more than u32::MAX past it cannot arise from a PE file. What the table holds can still point outside the image, but checked_sub/try_from would not detect that; it would need a check against the image size. PR #2420 (open) makes the change described here.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/2412#issuecomment-7167299261) <!-- victory-issue-triage v1 verdict=answered seen=2026-11-25T13:07:30Z at=2026-11-25T15:45:33Z --> Automated triage for the maintainers. Read against main (da82e44): in `crates/victory-pe/src/image.rs`, `parse_exports`, the address `object` (0.41) hands back is the image base plus the 32-bit RVA stored in the export address table. `address.wrapping_sub(image_base) as u32` undoes exactly that sum, so it always recovers the original table value; an export address below the image base or more than `u32::MAX` past it cannot arise from a PE file. What the table holds can still point outside the image, but `checked_sub`/`try_from` would not detect that; it would need a check against the image size. PR #2420 (open) makes the change described here. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#2412
No description provided.