pe: reject entry points outside the mapped image #2593

Open
XeNS1 wants to merge 1 commit from upstream-pr/2595 into main
XeNS1 commented 2026-11-25 16:25:45 +00:00 (Migrated from github.com)

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


An image with a nonzero AddressOfEntryPoint >= SizeOfImage currently parses successfully. The loader retains that original RVA and later calls base + entry_rva for an executable or DllMain, after prepare() has cleared the entry point in the copy given to Windows. Reject the invalid RVA in ImageInfo::parse before it reaches those calls.

Zero still denotes an absent entry point; existing acceptance of in-image RVAs is preserved. This only checks the declared mapped image extent, without introducing section, executable-permission or file-backing requirements. Two hand-built PE32+ tests cover EXE/DLL inputs at the boundary, beyond it and at u32::MAX, plus zero, a normal in-image RVA and the last in-image byte (12 cases).

Claim: PE-ENTRY-POINT-IMAGE-BOUND, coordination comment. This is separate from TLS callback checks (#324, #2532) and export address validation (#2412).

Validation on Linux x86-64 with Rust/Cargo 1.100.0, two build/test workers:

  • Regression check before the fix: the new rejection test fails because entry RVA 0x2000 is accepted for an image of size 0x2000; the new control test passes. Both new tests pass after the fix.
  • Full cargo test -p victory-pe --locked --offline -j 2 -- --test-threads=2: 34 passed, 4 failed. A separate clean checkout of base 67e8ae1 gives 32 passed and the same four failures: parses_own_test_binary, rejects_iat_outside_image, rva_to_file_offset_maps_entry_point, and rva_to_file_offset_rejects_offsets_past_4_gib. These existing tests expect their own executable to be a Windows PE; on Linux it is ELF (Unknown file magic). No tests were changed or disabled to conceal this.
  • With those four Windows-dependent cases excluded through test-runner arguments: 34 passed, 4 filtered out; doc tests passed (0 tests).
  • cargo clippy -p victory-pe --all-targets --all-features --locked --offline -j 2 -- -D warnings, package rustfmt check, git diff --check, and asset policy (184 repository files / 1 staged file) pass.

Windows and the pinned Rust 1.98.1 toolchain were not run locally; the repository's Windows CI remains the full-suite check. All new fixtures are generated from source in memory. No game files were accessed or included, and no guest code was executed.

Reference: Microsoft PE format specification, Optional Header standard / Windows-specific fields.

AI-assisted implementation and validation: OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6608864775 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2595). Originally posted by [XeNS1](https://github.com/XeNS1) on 2026-11-25T16:25:45Z. --- An image with a nonzero `AddressOfEntryPoint >= SizeOfImage` currently parses successfully. The loader retains that original RVA and later calls `base + entry_rva` for an executable or `DllMain`, after `prepare()` has cleared the entry point in the copy given to Windows. Reject the invalid RVA in `ImageInfo::parse` before it reaches those calls. Zero still denotes an absent entry point; existing acceptance of in-image RVAs is preserved. This only checks the declared mapped image extent, without introducing section, executable-permission or file-backing requirements. Two hand-built PE32+ tests cover EXE/DLL inputs at the boundary, beyond it and at `u32::MAX`, plus zero, a normal in-image RVA and the last in-image byte (12 cases). Claim: **PE-ENTRY-POINT-IMAGE-BOUND**, [coordination comment](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7167816292). This is separate from TLS callback checks (#324, #2532) and export address validation (#2412). Validation on Linux x86-64 with Rust/Cargo 1.100.0, two build/test workers: - Regression check before the fix: the new rejection test fails because entry RVA `0x2000` is accepted for an image of size `0x2000`; the new control test passes. Both new tests pass after the fix. - Full `cargo test -p victory-pe --locked --offline -j 2 -- --test-threads=2`: 34 passed, 4 failed. A separate clean checkout of base `67e8ae1` gives 32 passed and the **same four failures**: `parses_own_test_binary`, `rejects_iat_outside_image`, `rva_to_file_offset_maps_entry_point`, and `rva_to_file_offset_rejects_offsets_past_4_gib`. These existing tests expect their own executable to be a Windows PE; on Linux it is ELF (`Unknown file magic`). No tests were changed or disabled to conceal this. - With those four Windows-dependent cases excluded through test-runner arguments: 34 passed, 4 filtered out; doc tests passed (0 tests). - `cargo clippy -p victory-pe --all-targets --all-features --locked --offline -j 2 -- -D warnings`, package rustfmt check, `git diff --check`, and asset policy (184 repository files / 1 staged file) pass. Windows and the pinned Rust 1.98.1 toolchain were not run locally; the repository's Windows CI remains the full-suite check. All new fixtures are generated from source in memory. No game files were accessed or included, and no guest code was executed. Reference: [Microsoft PE format specification](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format), Optional Header standard / Windows-specific fields. AI-assisted implementation and validation: OpenAI Codex.
lcg007xd-c commented 2026-11-25 22:03:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-11-25T21:19:51Z.

Review: APPROVED


Verified on Linux (Rust 1.99.0)

Branch: current main (13f91ca) + this PR (merges cleanly; the PR is one commit behind main).

  • cargo test --locked -p victory-pe -- --skip parses_own_test_binary --skip rejects_iat_outside_image --skip rva_to_file_offset_maps_entry_point --skip rva_to_file_offset_rejects_offsets_past_4_gib: 34 passed. The four skipped tests need the test executable to be a PE and fail on Linux on main too, as the description says.
  • With the new entry_rva >= size_of_image check disabled, rejects_entry_points_outside_the_image fails and preserves_absent_and_in_image_entry_points still passes. So the test pins the fix, and the in-image and zero cases are unchanged.
  • cargo clippy --locked --target x86_64-pc-windows-msvc -p victory-pe --all-targets -- -D warnings: clean, same as main.

Review

The check covers the consumers the description names. crates/victory-loader/src/windows.rs:374 (DllMain) and :410 (EXE entry) both transmute(self.base() + self.info.entry_rva as usize) after testing only for entry_rva == 0. Neither bounds the RVA. prepare re-parses the copy with its entry zeroed (prepare.rs:189 asserts entry_rva == 0), and zero is still accepted, so that path is unaffected. apps/victory/src/census.rs:196 builds an ImageInfo directly and doesn't go through parse.

No defect found. The check is deliberately loose: an RVA inside SizeOfImage but in a gap between sections, or in a non-executable section, still parses. That's fine for this PR's stated scope, and the description says so.

No overlapping open PR found. This merges cleanly with #2630 and #2741, which also edit ImageInfo::parse.

Not verified

  • Windows-only: loading real title binaries through victory-loader.

Reviewed with Claude Code.

<!-- greyfinch-sync:Marvisak/VIctory:review:6065134865 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2595#pullrequestreview-6065134865). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T21:19:51Z. **Review:** APPROVED --- ### Verified on Linux (Rust 1.99.0) Branch: current `main` (13f91ca) + this PR (merges cleanly; the PR is one commit behind main). - `cargo test --locked -p victory-pe -- --skip parses_own_test_binary --skip rejects_iat_outside_image --skip rva_to_file_offset_maps_entry_point --skip rva_to_file_offset_rejects_offsets_past_4_gib`: 34 passed. The four skipped tests need the test executable to be a PE and fail on Linux on main too, as the description says. - With the new `entry_rva >= size_of_image` check disabled, `rejects_entry_points_outside_the_image` fails and `preserves_absent_and_in_image_entry_points` still passes. So the test pins the fix, and the in-image and zero cases are unchanged. - `cargo clippy --locked --target x86_64-pc-windows-msvc -p victory-pe --all-targets -- -D warnings`: clean, same as main. ### Review The check covers the consumers the description names. `crates/victory-loader/src/windows.rs:374` (DllMain) and `:410` (EXE entry) both `transmute(self.base() + self.info.entry_rva as usize)` after testing only for `entry_rva == 0`. Neither bounds the RVA. `prepare` re-parses the copy with its entry zeroed (`prepare.rs:189` asserts `entry_rva == 0`), and zero is still accepted, so that path is unaffected. `apps/victory/src/census.rs:196` builds an `ImageInfo` directly and doesn't go through `parse`. No defect found. The check is deliberately loose: an RVA inside `SizeOfImage` but in a gap between sections, or in a non-executable section, still parses. That's fine for this PR's stated scope, and the description says so. No overlapping open PR found. This merges cleanly with #2630 and #2741, which also edit `ImageInfo::parse`. ### Not verified - Windows-only: loading real title binaries through `victory-loader`. Reviewed with Claude Code.
Marvisak commented 2026-11-25 23:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:22:33Z.


Automated triage for the maintainers.

Proposed close: a guard for a case that does not occur. The check in ImageInfo::parse (victory-pe/src/image.rs) is correct as written, and CI (check) passes. But the only images whose entry point VIctory calls are the title's own executable and its DLLs. Those are well-formed images, and their entry points lie inside them. A hand-made PE with AddressOfEntryPoint >= SizeOfImage is not an input the loader meets, and the inspect commands only print the field. This is the same kind of hardening as the earlier TLS-callback bounds PR (#324), which was also proposed for closing.

This PR will be closed in 48 hours unless the author pushes a change (for example a real image that reaches this path) or a maintainer removes the triage: proposed close label.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176283427 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2595#issuecomment-7176283427). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:22:33Z. --- <!-- victory-triage v1 head=9351470f5159f5369c434e5426eaffb3f2ca7174 verdict=proposed-close at=2026-11-25T22:22:26Z --> Automated triage for the maintainers. **Proposed close: a guard for a case that does not occur.** The check in `ImageInfo::parse` (`victory-pe/src/image.rs`) is correct as written, and CI (`check`) passes. But the only images whose entry point VIctory calls are the title's own executable and its DLLs. Those are well-formed images, and their entry points lie inside them. A hand-made PE with `AddressOfEntryPoint >= SizeOfImage` is not an input the loader meets, and the inspect commands only print the field. This is the same kind of hardening as the earlier TLS-callback bounds PR (#324), which was also proposed for closing. This PR will be closed in 48 hours unless the author pushes a change (for example a real image that reaches this path) or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2595:upstream-pr/2595'
git switch 'upstream-pr/2595'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2595'
git switch 'upstream-pr/2595'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2595'
git switch 'upstream-pr/2595'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2595'
git switch 'main'
git merge --squash 'upstream-pr/2595'
git switch 'main'
git merge --ff-only 'upstream-pr/2595'
git switch 'main'
git merge 'upstream-pr/2595'
git push origin 'main'
Sign in to join this conversation.
No reviewers
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!2593
No description provided.