pe: reject RVA mappings outside the file #26

Closed
zerkend wants to merge 0 commits from upstream-pr/26 into main
zerkend commented 2026-11-21 18:06:58 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by zerkend on 2026-11-21T18:06:58Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6532529666 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/26). Originally posted by [zerkend](https://github.com/zerkend) on 2026-11-21T18:06:58Z. --- **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
omonkeyz commented 2026-11-22 13:13:15 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:13:15Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079653030 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/26#issuecomment-7079653030). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:13:15Z. --- 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

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
omonkeyz/xbox-emulator!26
No description provided.