Skip to content

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

Merged
Marvisak merged 2 commits into
Marvisak:mainfrom
AndyLatimer:fix/pe-rva-offset-overflow
Nov 24, 2026
Merged

Marvisak merged 2 commits into
Marvisak:mainfrom
AndyLatimer:fix/pe-rva-offset-overflow

Conversation

@AndyLatimer

@AndyLatimer AndyLatimer commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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 and others added 2 commits November 24, 2026 00:19
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 <noreply@anthropic.com>
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.
@AndyLatimer AndyLatimer changed the title PE: checked file offset in rva_to_file_offset PE: checked offsets in rva_to_file_offset and layout, remove dbg_tls Nov 23, 2026
@DaviTostes

Copy link
Copy Markdown

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; Build: make workspace tests run on Linux #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

Copy link
Copy Markdown
Contributor

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.

@Marvisak
Marvisak merged commit cc51927 into Marvisak:main Nov 24, 2026
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
PE: checked offsets in rva_to_file_offset and layout, remove dbg_tls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants