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

Open
opened 2026-11-25 13:07:30 +00:00 by pushkarreddyy · 1 comment
pushkarreddyy commented 2026-11-25 13:07:30 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-25T13:07:30Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6605185657 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2412). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-25T13:07:30Z. --- ### 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.*
Marvisak commented 2026-11-25 16:09:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:45:57Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167299261 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2412#issuecomment-7167299261). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:45:57Z. --- <!-- 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)_
Sign in to join this conversation.
No labels
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.

Reference
Marvisak/VIctory#2410
No description provided.