PE: reject out-of-range export addresses in parse_exports (fixes #2412) #2420

Closed
github-bot wants to merge 1 commit from github-bot/gh-2420 into main AGit
Owner

@⁠pushkarreddyy on GitHub · 2026-11-25 13:11 UTC · original
pushkarreddyy:fix/pe-export-rva-overflow → main · +26 −3 · 1 files · 1 commits · closed without merging

Fixes #2412.

Root Cause

In crates/victory-pe/src/image.rs (parse_exports), export RVAs were computed from object's ReadTarget::Address { address } using address.wrapping_sub(image_base) as u32. If a malformed PE export address is below image_base or address - image_base > u32::MAX, wrapping_sub and as u32 silently wrap/truncate to an invalid 32-bit RVA instead of returning PeError::Malformed.

Implementation Details

  • Extracted export_rva(address: u64, image_base: u64) -> Result<u32, PeError> using checked_sub(image_base) and u32::try_from, returning PeError::Malformed on underflow or u32 overflow.
  • Updated parse_exports to call export_rva(address, image_base)?.

Verification

  • Added export_rva_rejects_underflow_and_u32_overflow unit test in crates/victory-pe/src/image.rs verifying valid RVAs, underflow below image_base, and overflow past u32::MAX.
  • CI check (workspace build, clippy -D warnings, and tests) is green.

Scope & Limitations

  • Valid exports and forwarded exports are unaffected.
  • No title files or proprietary assets were used.
**@⁠pushkarreddyy** on GitHub · 2026-11-25 13:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2420) `pushkarreddyy:fix/pe-export-rva-overflow` → `main` · +26 −3 · 1 files · 1 commits · closed without merging Fixes #2412. ### Root Cause In `crates/victory-pe/src/image.rs` (`parse_exports`), export RVAs were computed from `object`'s `ReadTarget::Address { address }` using `address.wrapping_sub(image_base) as u32`. If a malformed PE export address is below `image_base` or `address - image_base > u32::MAX`, `wrapping_sub` and `as u32` silently wrap/truncate to an invalid 32-bit RVA instead of returning `PeError::Malformed`. ### Implementation Details - Extracted `export_rva(address: u64, image_base: u64) -> Result<u32, PeError>` using `checked_sub(image_base)` and `u32::try_from`, returning `PeError::Malformed` on underflow or `u32` overflow. - Updated `parse_exports` to call `export_rva(address, image_base)?`. ### Verification - Added `export_rva_rejects_underflow_and_u32_overflow` unit test in `crates/victory-pe/src/image.rs` verifying valid RVAs, underflow below `image_base`, and overflow past `u32::MAX`. - CI `check` (workspace build, clippy `-D warnings`, and tests) is green. ### Scope & Limitations - Valid exports and forwarded exports are unaffected. - No title files or proprietary assets were used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:05:18 +00:00
Author
Owner

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

Hi @⁠Marvisak — this PR resolves #2412 (rejecting out-of-range export addresses in parse_exports with PeError::Malformed instead of wrapping/truncating), with unit tests and CI (check) passing. Ready for review and merge whenever convenient!

**@⁠pushkarreddyy** on GitHub · 2026-11-25 13:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2420#issuecomment-7164021630) Hi @⁠Marvisak — this PR resolves #2412 (rejecting out-of-range export addresses in `parse_exports` with `PeError::Malformed` instead of wrapping/truncating), with unit tests and CI (`check`) passing. Ready for review and merge whenever convenient!
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 13:53 UTC · original

Reviewed: wrapping_sub → checked_sub + u32::try_from is the right fix — a PE64 export RVA must be a u32 above the image base. Test covers both reject directions and the happy path.

**@⁠kotekompotek** on GitHub · 2026-11-25 13:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2420#issuecomment-7164436212) Reviewed: `wrapping_sub` → `checked_sub` + `u32::try_from` is the right fix — a PE64 export RVA must be a u32 above the image base. Test covers both reject directions and the happy path.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-25 14:19 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)

**@⁠pushkarreddyy** on GitHub · 2026-11-25 14:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2420#issuecomment-7165090211) 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)
Author
Owner

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

Automated triage for the maintainers.

Proposed close. The error this adds cannot happen. In image.rs parse_exports, the address comes from object'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 on main, address.wrapping_sub(image_base) as u32 always gives back the exact RVA; the value cannot be below the image base or more than u32::MAX above it except through a wrap that the current code already undoes correctly, and the new export_rva would 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

**@⁠Marvisak** on GitHub · 2026-11-25 15:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2420#issuecomment-7166914425) <!-- victory-triage v1 head=4fe4731595748270e2bc86d42c320f3c8cbe3efa verdict=proposed-close at=2026-11-25T15:30:00Z --> Automated triage for the maintainers. **Proposed close.** The error this adds cannot happen. In `image.rs` `parse_exports`, the address comes from `object`'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 on `main`, `address.wrapping_sub(image_base) as u32` always gives back the exact RVA; the value cannot be below the image base or more than `u32::MAX` above it except through a wrap that the current code already undoes correctly, and the new `export_rva` would 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](https://claude.ai/code)_
github-bot closed this pull request 2026-11-26 15:19:50 +00:00
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 13:19 UTC · original · approved these changes

Verified against origin/main (940d32f):

  • Rejecting out-of-range / underflowing / overflowing export RVAs in parse_exports (#2412) is clean and well-tested.
  • cargo test -p victory-pe: 37/37 passed (including export_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).

**@⁠DenRakEiw** on GitHub · 2026-11-25 13:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2420#pullrequestreview-6058345761) · **approved these changes** Verified against `origin/main` (`940d32f`): - Rejecting out-of-range / underflowing / overflowing export RVAs in `parse_exports` (`#2412`) is clean and well-tested. - `cargo test -p victory-pe`: 37/37 passed (including `export_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).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 13:25 UTC · original · approved these changes

Tested locally: merged into main 940d32f69b, cargo test -p victory-pe --locked on 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.

**@⁠catminou4** on GitHub · 2026-11-25 13:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2420#pullrequestreview-6058436439) · **approved these changes** Tested locally: merged into main 940d32f69b, `cargo test -p victory-pe --locked` on 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.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-26 15:19 UTC · original

Closing this PR after reviewing the triage verification on main:

  • In parse_exports, object's generic export iterator constructs addresses as image_base + rva, so address.wrapping_sub(image_base) as u32 on main already recovers the exact 32-bit RVA (including wrapped sums).
  • Rejecting wrapped values would break valid cases that main already handles correctly.

Thank you for the verification.

AI-assisted: yes (Gemini 4 Neon)

**@⁠pushkarreddyy** on GitHub · 2026-11-26 15:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2420#issuecomment-7196094365) Closing this PR after reviewing the triage verification on `main`: - In `parse_exports`, `object`'s generic export iterator constructs addresses as `image_base + rva`, so `address.wrapping_sub(image_base) as u32` on `main` already recovers the exact 32-bit RVA (including wrapped sums). - Rejecting wrapped values would break valid cases that `main` already handles correctly. Thank you for the verification. AI-assisted: yes (Gemini 4 Neon)

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!2420
No description provided.