test(pe): cover header layout offsets #311

Closed
CesarLopesO wants to merge 2 commits from upstream-pr/311 into main
CesarLopesO commented 2026-11-24 02:14:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by CesarLopesO on 2026-11-24T02:14:20Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573063733 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/311). Originally posted by [CesarLopesO](https://github.com/CesarLopesO) on 2026-11-24T02:14:20Z. --- ## 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.
jeremygold02 commented 2026-11-24 06:55:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:18:59Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121906137 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/311#issuecomment-7121906137). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:18:59Z. --- 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)
TrashTalker3460 commented 2026-11-24 06:56:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TrashTalker3460 on 2026-11-24T05:51:09Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123335258 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/311#issuecomment-7123335258). Originally posted by [TrashTalker3460](https://github.com/TrashTalker3460) on 2026-11-24T05:51:09Z. --- 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._
mercuryVM commented 2026-11-24 08:36:05 +00:00 (Migrated from github.com)

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

Review: APPROVED


Tested 95f5390 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (267 passed, 0 failed).

These are test-only additions. They cover e_lfanew-relative offsets, the NumberOfRvaAndSizes bound on data directories, and rejection of truncated DOS and optional headers, all on synthetic buffers. The expected offsets (0x44, 0x58, and data directory + 8) match the PE32+ layout.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6036008245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/311#pullrequestreview-6036008245). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T08:36:05Z. **Review:** APPROVED --- Tested 95f5390 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (267 passed, 0 failed). These are test-only additions. They cover `e_lfanew`-relative offsets, the `NumberOfRvaAndSizes` bound on data directories, and rejection of truncated DOS and optional headers, all on synthetic buffers. The expected offsets (0x44, 0x58, and data directory + 8) match the PE32+ layout. No issues found. AI-assisted (Claude Code).
mercuryVM commented 2026-11-24 13:09:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T13:09:59Z.

Review: APPROVED


Re-tested 1251a24 on Windows 11, RTX 5070, MSVC: cargo test -p victory-pe passes, 20 tests on mercuryVM/VIctory main with this head merged (the earlier head is already there).

  • The three new layout tests pin the DOS-pointer arithmetic (file_header_offset 0x44 and optional_header_offset 0x58 for e_lfanew 0x40), the declared directory count, and truncated headers. They pass both with and without the SizeOfOptionalHeader check from #396, so they don't depend on which of the two lands first.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6039762947 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/311#pullrequestreview-6039762947). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T13:09:59Z. **Review:** APPROVED --- Re-tested 1251a24 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-pe` passes, 20 tests on mercuryVM/VIctory main with this head merged (the earlier head is already there). - The three new layout tests pin the DOS-pointer arithmetic (`file_header_offset` 0x44 and `optional_header_offset` 0x58 for `e_lfanew` 0x40), the declared directory count, and truncated headers. They pass both with and without the `SizeOfOptionalHeader` check from #396, so they don't depend on which of the two lands first. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 00:05:22 +00:00
Marvisak commented 2026-11-25 00:06:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:01:19Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148049355 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/311#issuecomment-7148049355). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:01:19Z. --- 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

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