pe: reject RVA mappings outside the file #26

Closed
github-bot wants to merge 1 commit from gh-pr/26/head into gh-pr/26/base
Owner

@⁠zerkend on GitHub · 2026-11-21 18:06 UTC · original
zerkend:codex/pe-rva-validation → main · +86 −2 · 2 files · 63 commits · closed without merging

Library / area: tombox-pe

Exports changed: none

PeFile::rva_to_offset could return Ok with a file offset at or beyond EOF. A synthetic 512-byte PE reproduced both a section mapping to 4294967040 and a header mapping to 768. Malformed section ranges remain inspectable through the parser's notes, but their nonexistent bytes must not map successfully.

Check section offset addition and require the resulting byte to exist. Apply the same EOF check to the header fallback. Keep valid bytes in partially truncated sections mappable, and preserve rejection of virtual-only/BSS bytes.

Source of behaviour: the method's documented file-backed mapping contract and the existing bounds-checked Reader API; fixtures are hand-built PE32+ headers.

Validation (Windows, Rust 1.100):

  • cargo test --locked -p tombox-pe: 13 passed.

  • The new cases fail against the original implementation (3 failed, 1 passed), then all 4 pass with the fix.

  • git diff --check passes.

  • No game/console files or binaries included

**@⁠zerkend** on GitHub · 2026-11-21 18:06 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/26) `zerkend:codex/pe-rva-validation` → `main` · +86 −2 · 2 files · 63 commits · closed without merging **Library / area:** tombox-pe **Exports changed:** none `PeFile::rva_to_offset` could return `Ok` with a file offset at or beyond EOF. A synthetic 512-byte PE reproduced both a section mapping to 4294967040 and a header mapping to 768. Malformed section ranges remain inspectable through the parser's notes, but their nonexistent bytes must not map successfully. Check section offset addition and require the resulting byte to exist. Apply the same EOF check to the header fallback. Keep valid bytes in partially truncated sections mappable, and preserve rejection of virtual-only/BSS bytes. **Source of behaviour:** the method's documented file-backed mapping contract and the existing bounds-checked Reader API; fixtures are hand-built PE32+ headers. **Validation** (Windows, Rust 1.100): - `cargo test --locked -p tombox-pe`: 13 passed. - The new cases fail against the original implementation (3 failed, 1 passed), then all 4 pass with the fix. - `git diff --check` passes. - [x] No game/console files or binaries included
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:07:39 +00:00
github-bot closed this pull request 2026-11-26 06:07:39 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:13 UTC · original

Main's history was rewritten, which auto-closed this PR (sorry for the noise). Superseded: rva_to_offset on main already has the same checked bound.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:13 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/26#issuecomment-7079653030) Main's history was rewritten, which auto-closed this PR (sorry for the noise). Superseded: rva_to_offset on main already has the same checked bound.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.