test(pe): cover header layout offsets #311

Closed
github-bot wants to merge 2 commits from gh-pr/311/head into gh-pr/311/base
Owner

@⁠CesarLopesO on GitHub · 2026-11-24 02:14 UTC · original
CesarLopesO:test/pe-layout-offsets → main · +45 −0 · 1 files · 2 commits · closed without merging

Summary

  • Add unit coverage for the PE header offset helpers.
  • Verify file and optional header offsets follow the DOS e_lfanew pointer.
  • Verify data-directory offsets respect the declared entry count.
  • Verify truncated DOS and optional headers are rejected.

Validation

Passed:

  • cargo test -p victory-pe --lib layout::tests — 4 passed.
  • rustfmt --edition 2024 --check crates/victory-pe/src/layout.rs
  • cargo clippy -p victory-pe --all-targets -- -D warnings
  • cargo xtask policy — 151 files.
  • git diff --check

Environment note:

cargo test --locked -p victory-pe reports 4 failures in existing image::tests on Debian/Linux. These tests parse the current test executable as a PE32+ binary, but Linux produces an ELF executable. The failures are in unchanged crates/victory-pe/src/image.rs; all new layout tests pass.

**@⁠CesarLopesO** on GitHub · 2026-11-24 02:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/311) `CesarLopesO:test/pe-layout-offsets` → `main` · +45 −0 · 1 files · 2 commits · closed without merging ## Summary - Add unit coverage for the PE header offset helpers. - Verify file and optional header offsets follow the DOS `e_lfanew` pointer. - Verify data-directory offsets respect the declared entry count. - Verify truncated DOS and optional headers are rejected. ## Validation Passed: - `cargo test -p victory-pe --lib layout::tests` — 4 passed. - `rustfmt --edition 2024 --check crates/victory-pe/src/layout.rs` - `cargo clippy -p victory-pe --all-targets -- -D warnings` - `cargo xtask policy` — 151 files. - `git diff --check` Environment note: `cargo test --locked -p victory-pe` reports 4 failures in existing `image::tests` on Debian/Linux. These tests parse the current test executable as a PE32+ binary, but Linux produces an ELF executable. The failures are in unchanged `crates/victory-pe/src/image.rs`; all new layout tests pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:52 +00:00
github-bot closed this pull request 2026-11-26 03:58:52 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:18 UTC · original

Tested PR #311 at head 95f5390a5cebc8ed9ab2349960dd7e93e26b6064 (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at 95f5390a5cebc8ed9ab2349960dd7e93e26b6064.

  • cargo test --locked -p victory-pe --lib layout::tests — passed (ok. 4 passed; 0 failed; 0 ignored; 0 measured; 6 filtered out; finished in 0.00s ); cases: layout::tests::reads_reject_overflowing_offsets, layout::tests::data_directory_offsets_respect_declared_entry_count, layout::tests::header_offsets_follow_the_dos_header_pointer, layout::tests::header_offset_helpers_reject_truncated_headers.

Behavior covered: Checks PE layout offset helpers use the DOS header pointer, respect declared directory counts, and reject truncated/overflowing headers.
Code: crates/victory-pe/src/layout.rs

**@⁠jeremygold02** on GitHub · 2026-11-24 04:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/311#issuecomment-7121906137) Tested PR #311 at head `95f5390a5cebc8ed9ab2349960dd7e93e26b6064` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `95f5390a5cebc8ed9ab2349960dd7e93e26b6064`. - `cargo test --locked -p victory-pe --lib layout::tests` — passed (ok. 4 passed; 0 failed; 0 ignored; 0 measured; 6 filtered out; finished in 0.00s ); cases: layout::tests::reads_reject_overflowing_offsets, layout::tests::data_directory_offsets_respect_declared_entry_count, layout::tests::header_offsets_follow_the_dos_header_pointer, layout::tests::header_offset_helpers_reject_truncated_headers. Behavior covered: Checks PE layout offset helpers use the DOS header pointer, respect declared directory counts, and reject truncated/overflowing headers. Code: [crates/victory-pe/src/layout.rs](https://github.com/Marvisak/VIctory/blob/95f5390a5cebc8ed9ab2349960dd7e93e26b6064/crates/victory-pe/src/layout.rs)
Author
Owner

@⁠ghost on GitHub · 2026-11-24 05:51 UTC · original

Note on head 95f5390: this test and #396 can't both land as written.

data_directory_offsets_respect_declared_entry_count (crates/victory-pe/src/layout.rs:114) builds a header whose SizeOfOptionalHeader is 0 and expects data_directory_offset(&data, 0) == Some(first). #396 bounds the lookup to SizeOfOptionalHeader (its layout.rs:83–97), so the same input returns None. If #396 goes in, setting SizeOfOptionalHeader in the fixture would keep the test meaningful.

Read-only review, nothing built. AI-assisted (Claude Code); the claim above was checked against this head and main at d2a4bae. Context: the triage in #366.

**@⁠ghost** on GitHub · 2026-11-24 05:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/311#issuecomment-7123335258) Note on head `95f5390`: this test and #396 can't both land as written. `data_directory_offsets_respect_declared_entry_count` (`crates/victory-pe/src/layout.rs:114`) builds a header whose `SizeOfOptionalHeader` is 0 and expects `data_directory_offset(&data, 0) == Some(first)`. #396 bounds the lookup to `SizeOfOptionalHeader` (its `layout.rs:83–97`), so the same input returns `None`. If #396 goes in, setting `SizeOfOptionalHeader` in the fixture would keep the test meaningful. _Read-only review, nothing built. AI-assisted (Claude Code); the claim above was checked against this head and `main` at `d2a4bae`. Context: the triage in #366._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:01 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1171. Three small tests for layout.rs offset helpers; correct (one 'truncated header' assert passes only because the count field reads 0). Fully covered by #1171's layout tests, and the two collide in the same test module.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/311#issuecomment-7148049355) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1171. Three small tests for layout.rs offset helpers; correct (one 'truncated header' assert passes only because the count field reads 0). Fully covered by #1171's layout tests, and the two collide in the same test module. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!311
No description provided.