fix(pe): validate section raw data bounds #219

Merged
DiegoFR20 merged 1 commit from upstream-pr/219 into main 2026-11-25 00:10:14 +00:00
DiegoFR20 commented 2026-11-24 01:33:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DiegoFR20 on 2026-11-24T01:33:51Z.


Summary

  • Add validation for PE section raw-data boundaries.
  • Reject sections whose declared raw-data range exceeds the input file.
  • Add regression tests covering truncated sections, exact EOF boundaries, and zero-sized raw sections.

Motivation

ImageInfo::parse() previously accepted a synthetic PE image whose section header declared more raw data than the file contained.

This could allow rva_to_file_offset() to return an offset beyond the available file bytes.

Testing

  • cargo test -p victory-pe
  • cargo test --workspace
  • cargo clippy -p victory-pe --all-targets -- -D warnings

All passed locally.

Compatibility question

Should the parser strictly reject sections whose declared raw-data ranges extend beyond EOF, or does VIctory intentionally support partially truncated PE images?

Opening as a draft to confirm the expected behavior before requesting a merge.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572578544 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/219). Originally posted by [DiegoFR20](https://github.com/DiegoFR20) on 2026-11-24T01:33:51Z. --- ## Summary - Add validation for PE section raw-data boundaries. - Reject sections whose declared raw-data range exceeds the input file. - Add regression tests covering truncated sections, exact EOF boundaries, and zero-sized raw sections. ## Motivation `ImageInfo::parse()` previously accepted a synthetic PE image whose section header declared more raw data than the file contained. This could allow `rva_to_file_offset()` to return an offset beyond the available file bytes. ## Testing - `cargo test -p victory-pe` - `cargo test --workspace` - `cargo clippy -p victory-pe --all-targets -- -D warnings` All passed locally. ## Compatibility question Should the parser strictly reject sections whose declared raw-data ranges extend beyond EOF, or does VIctory intentionally support partially truncated PE images? Opening as a draft to confirm the expected behavior before requesting a merge.
jeremygold02 commented 2026-11-24 06:55:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T05:14:08Z.


Thanks @DiegoFR20 for tightening the raw section-data bounds while preserving valid boundary cases.

I tested commit e57e76a7b4058e50d665ddcc9a11eb3cd4de4e7d with:

cargo test --locked -p victory-pe --lib section -- --test-threads=1

All 3 targeted tests passed (0 failed; 7 filtered):

These are synthetic PE parser boundary tests; they do not load a real executable.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122754200 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/219#issuecomment-7122754200). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T05:14:08Z. --- Thanks @DiegoFR20 for tightening the raw section-data bounds while preserving valid boundary cases. I tested commit `e57e76a7b4058e50d665ddcc9a11eb3cd4de4e7d` with: ``` cargo test --locked -p victory-pe --lib section -- --test-threads=1 ``` All 3 targeted tests passed (0 failed; 7 filtered): - [`rejects_section_extending_beyond_file`](https://github.com/Marvisak/VIctory/blob/e57e76a7b4058e50d665ddcc9a11eb3cd4de4e7d/crates/victory-pe/src/image.rs#L534) rejects raw section data whose end exceeds the input image. - [`accepts_section_ending_at_file_boundary`](https://github.com/Marvisak/VIctory/blob/e57e76a7b4058e50d665ddcc9a11eb3cd4de4e7d/crates/victory-pe/src/image.rs#L563) accepts data ending exactly at EOF. - [`accepts_section_with_zero_raw_size`](https://github.com/Marvisak/VIctory/blob/e57e76a7b4058e50d665ddcc9a11eb3cd4de4e7d/crates/victory-pe/src/image.rs#L580) accepts a virtual section with no raw bytes. These are synthetic PE parser boundary tests; they do not load a real executable.
mercuryVM commented 2026-11-24 10:11:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:11:36Z.

Review: APPROVED


Tested e57e76a on Windows 11, RTX 5070, MSVC: cargo test -p victory-pe 10 passed, cargo clippy -p victory-pe --all-targets clean.

  • The bound check uses u64 with checked_add, so an overflowing PointerToRawData + SizeOfRawData is also rejected. The check runs before any data directory is resolved, so rva_to_file_offset can no longer hand out an offset past EOF.
  • Skipping file_size == 0 matches how BSS-style sections work. I also checked the tests: opt + 240 is the right section-table offset for the PE32+ optional header that synthetic_image builds.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037311407 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/219#pullrequestreview-6037311407). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T10:11:36Z. **Review:** APPROVED --- Tested e57e76a on Windows 11, RTX 5070, MSVC: `cargo test -p victory-pe` 10 passed, `cargo clippy -p victory-pe --all-targets` clean. - The bound check uses `u64` with `checked_add`, so an overflowing `PointerToRawData + SizeOfRawData` is also rejected. The check runs before any data directory is resolved, so `rva_to_file_offset` can no longer hand out an offset past EOF. - Skipping `file_size == 0` matches how BSS-style sections work. I also checked the tests: `opt + 240` is the right section-table offset for the PE32+ optional header that `synthetic_image` builds. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:03:02 +00:00
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!219
No description provided.