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

Manually merged
github merged 1 commit from gh-pr/219/head into gh-pr/219/base 2026-11-26 03:55:19 +00:00
Owner

@⁠DiegoFR20 on GitHub · 2026-11-24 01:33 UTC · original
DiegoFR20:investigation/pe-validation → main · +94 −1 · 1 files · 1 commits · merged 2026-11-25 00:10 UTC

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.

**@⁠DiegoFR20** on GitHub · 2026-11-24 01:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/219) `DiegoFR20:investigation/pe-validation` → `main` · +94 −1 · 1 files · 1 commits · merged 2026-11-25 00:10 UTC ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:55:17 +00:00
github manually merged commit e57e76a7b4 into gh-pr/219/base 2026-11-26 03:55:19 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 05:14 UTC · original

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.

**@⁠jeremygold02** on GitHub · 2026-11-24 05:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/219#issuecomment-7122754200) 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.
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!219
No description provided.