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

Merged
AndyLatimer merged 2 commits from upstream-pr/30 into main 2026-11-24 00:33:21 +00:00
AndyLatimer commented 2026-11-23 23:27:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-23T23:27:50Z.


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).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6570991980 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/30). Originally posted by [AndyLatimer](https://github.com/AndyLatimer) on 2026-11-23T23:27:50Z. --- 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).
upstream-sync closed this pull request 2026-11-24 06:50:58 +00:00
DaviTostes commented 2026-11-24 06:54:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:00:00Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7117591489 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/30#issuecomment-7117591489). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:00:00Z. --- 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).
lordon1a commented 2026-11-24 06:54:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T00:20:04Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7117958372 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/30#issuecomment-7117958372). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T00:20:04Z. --- 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.
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!30
No description provided.