PE: checked offsets in rva_to_file_offset and layout, remove dbg_tls #30

Manually merged
github merged 2 commits from gh-pr/30/head into gh-pr/30/base 2026-11-26 03:47:12 +00:00
Owner

@⁠AndyLatimer on GitHub · 2026-11-23 23:27 UTC · original
AndyLatimer:fix/pe-rva-offset-overflow → main · +37 −18 · 2 files · 2 commits · merged 2026-11-24 00:33 UTC

Two small checked-arithmetic fixes and a test cleanup in victory-pe:

  1. ImageInfo::rva_to_file_offset (image.rs): switches s.file_offset + delta to checked_add so a section header with PointerToRawData near 4 GiB returns None instead of overflowing u32 (panic in debug builds, wrapped offset in release). Adds regression test rva_to_file_offset_rejects_offsets_past_4_gib.
  2. PE layout helpers (layout.rs): switches read_u32, read_u64, optional_header_offset, file_header_offset and data_directory_offset to checked arithmetic so extreme offsets return None instead of overflowing. Adds regression test reads_reject_overflowing_offsets.
  3. Test cleanup (image.rs): removes the leftover print-only dbg_tls::dump_tls test (TLS presence is already asserted in parses_own_test_binary).

Testing

  • cargo test -p victory-pe: 6 passed, 0 failed.
  • cargo clippy -p victory-pe --all-targets: 0 warnings.
  • cargo xtask policy: pass (148 files).
  • Tested with synthetic inputs only (not run against a title).
**@⁠AndyLatimer** on GitHub · 2026-11-23 23:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/30) `AndyLatimer:fix/pe-rva-offset-overflow` → `main` · +37 −18 · 2 files · 2 commits · merged 2026-11-24 00:33 UTC Two small checked-arithmetic fixes and a test cleanup in `victory-pe`: 1. **`ImageInfo::rva_to_file_offset`** (`image.rs`): switches `s.file_offset + delta` to `checked_add` so a section header with `PointerToRawData` near 4 GiB returns `None` instead of overflowing `u32` (panic in debug builds, wrapped offset in release). Adds regression test `rva_to_file_offset_rejects_offsets_past_4_gib`. 2. **PE layout helpers** (`layout.rs`): switches `read_u32`, `read_u64`, `optional_header_offset`, `file_header_offset` and `data_directory_offset` to checked arithmetic so extreme offsets return `None` instead of overflowing. Adds regression test `reads_reject_overflowing_offsets`. 3. **Test cleanup** (`image.rs`): removes the leftover print-only `dbg_tls::dump_tls` test (TLS presence is already asserted in `parses_own_test_binary`). ## Testing - `cargo test -p victory-pe`: 6 passed, 0 failed. - `cargo clippy -p victory-pe --all-targets`: 0 warnings. - `cargo xtask policy`: pass (148 files). - Tested with synthetic inputs only (not run against a title).
A section whose PointerToRawData lies near 4 GiB made
file_offset + delta overflow: a panic in debug builds, a wrong offset in
release ones. The section now yields no offset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Removes the print-only dbg_tls test in image.rs (TLS presence is already asserted in parses_own_test_binary) and switches layout.rs offset helpers (read_u32, read_u64, optional_header_offset, file_header_offset, data_directory_offset) to checked arithmetic so extreme offsets return None instead of overflowing.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:10 +00:00
github manually merged commit ef22723e84 into gh-pr/30/base 2026-11-26 03:47:12 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:00 UTC · original

Could not run the Linux check for this head: it conflicts with #39 (the PR that makes the workspace build and test on Linux), so it cannot be stacked without a rebase.

  • Conflict: crates/victory-pe/src/image.rs, in the mod tests / dbg_tls region. This PR removes the leftover dbg_tls test and checks layout offsets; #39 adds #[cfg(windows)] gates around own_image and the tests that read the running binary. Both touch the same block.
  • The rest of the tree is clean; only that file conflicts.

A rebase of this branch onto #39 (or a version of it after #39 lands) would let me run cargo test --workspace here and report the result.

AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/30#issuecomment-7117591489) Could not run the Linux check for this head: it **conflicts with #39** (the PR that makes the workspace build and test on Linux), so it cannot be stacked without a rebase. - Conflict: `crates/victory-pe/src/image.rs`, in the `mod tests` / `dbg_tls` region. This PR removes the leftover `dbg_tls` test and checks layout offsets; #39 adds `#[cfg(windows)]` gates around `own_image` and the tests that read the running binary. Both touch the same block. - The rest of the tree is clean; only that file conflicts. A rebase of this branch onto #39 (or a version of it after #39 lands) would let me run `cargo test --workspace` here and report the result. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 00:20 UTC · original

Verified ef22723e8 on Windows 11 (x86_64-pc-windows-gnullvm, rustc 1.100.0, applied cleanly to main@35b054ec0): pass.

  • cargo xtask policy: 150 files ok
  • cargo test -p victory-pe: 6 passed, 0 failed (+1 new checked-offset test).

AI-assisted.

**@⁠lordon1a** on GitHub · 2026-11-24 00:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/30#issuecomment-7117958372) Verified `ef22723e8` on Windows 11 (`x86_64-pc-windows-gnullvm`, `rustc 1.100.0`, applied cleanly to `main@35b054ec0`): **pass**. - `cargo xtask policy`: 150 files ok - `cargo test -p victory-pe`: **6 passed, 0 failed** (+1 new checked-offset test). AI-assisted.
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!30
No description provided.