PE tests: parse a synthetic image so ImageInfo is covered on every host #257

Closed
github-bot wants to merge 1 commit from gh-pr/257/head into gh-pr/257/base
Owner

@⁠SkippySteve on GitHub · 2026-11-24 01:52 UTC · original
SkippySteve/victory-pr-own-next7 → main · +225 −0 · 1 files · 1 commits · closed without merging

The ImageInfo unit tests in victory-pe that cover imports, TLS and section mapping parse the test binary itself. That binary is a PE only on Windows, so on Linux they fail with Unknown file magic, and #235 limits them to Windows. This PR adds coverage that runs on every host and doesn't touch those tests or any non-test code.

What it adds

crates/victory-pe/tests/synthetic_image.rs builds a small PE32+ executable in memory: one section, a KERNEL32.dll import by name (with a hint) and by ordinal, and two TLS callbacks. It checks:

  • headers and sections: machine, DLL flag, timestamp, image base, entry point, subsystem, stack sizes
  • imports and their IAT slot RVAs
  • TLS callbacks, read in order up to the null terminator; a callback below the image base is reported as malformed
  • rva_to_file_offset: section data maps correctly, headers and the section end don't map, raw padding past the virtual size isn't section data, and an offset near 4 GiB doesn't wrap
  • an IAT running past SizeOfImage, including at the 4 GiB limit, is reported as Malformed
  • a non-AMD64 machine is reported as Unsupported, and truncated input errors without panicking

The image is built byte by byte in the test. No game data, fixtures or files on disk.

Testing

On Arch Linux (x86_64-unknown-linux-gnu):

  • cargo test -p victory-pe --test synthetic_image: 8 passed
  • cargo clippy -p victory-pe --all-targets -- -D warnings, cargo fmt --check and cargo xtask policy are clean
  • I checked that the tests catch regressions by temporarily breaking three checks in image.rs: the IAT bound, the virtual-size clamp and the TLS null terminator. Each one made a test fail.

cargo test -p victory-pe on Linux still shows the 4 existing own-binary failures from main. #235 handles those. I haven't run this on Windows; the new file uses only the public API and doesn't depend on the host.

**@⁠SkippySteve** on GitHub · 2026-11-24 01:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/257) `SkippySteve/victory-pr-own-next7` → `main` · +225 −0 · 1 files · 1 commits · closed without merging The `ImageInfo` unit tests in `victory-pe` that cover imports, TLS and section mapping parse the test binary itself. That binary is a PE only on Windows, so on Linux they fail with `Unknown file magic`, and #235 limits them to Windows. This PR adds coverage that runs on every host and doesn't touch those tests or any non-test code. ## What it adds `crates/victory-pe/tests/synthetic_image.rs` builds a small PE32+ executable in memory: one section, a `KERNEL32.dll` import by name (with a hint) and by ordinal, and two TLS callbacks. It checks: - headers and sections: machine, DLL flag, timestamp, image base, entry point, subsystem, stack sizes - imports and their IAT slot RVAs - TLS callbacks, read in order up to the null terminator; a callback below the image base is reported as malformed - `rva_to_file_offset`: section data maps correctly, headers and the section end don't map, raw padding past the virtual size isn't section data, and an offset near 4 GiB doesn't wrap - an IAT running past `SizeOfImage`, including at the 4 GiB limit, is reported as `Malformed` - a non-AMD64 machine is reported as `Unsupported`, and truncated input errors without panicking The image is built byte by byte in the test. No game data, fixtures or files on disk. ## Testing On Arch Linux (x86_64-unknown-linux-gnu): - `cargo test -p victory-pe --test synthetic_image`: 8 passed - `cargo clippy -p victory-pe --all-targets -- -D warnings`, `cargo fmt --check` and `cargo xtask policy` are clean - I checked that the tests catch regressions by temporarily breaking three checks in `image.rs`: the IAT bound, the virtual-size clamp and the TLS null terminator. Each one made a test fail. `cargo test -p victory-pe` on Linux still shows the 4 existing own-binary failures from `main`. #235 handles those. I haven't run this on Windows; the new file uses only the public API and doesn't depend on the host.
The ImageInfo unit tests that read imports, TLS and section mapping parse
the test binary itself, which is a PE only on Windows. Add an integration
test that builds a small PE32+ executable in memory (one section, a
KERNEL32.dll import by name and by ordinal, two TLS callbacks) and checks
headers, sections, imports and their IAT slots, TLS callback order,
rva_to_file_offset (padding past the virtual size, the 4 GiB limit), an
IAT running outside the image, other machines and truncated input.
No game data or files on disk.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:56:53 +00:00
github-bot closed this pull request 2026-11-26 03:56:53 +00:00
Author
Owner

@⁠CesarLopesO on GitHub · 2026-11-24 02:08 UTC · original

Independent validation on Debian 13 (Trixie).

I tested this PR locally with the following results:

  • cargo test --locked -p victory-pe --test synthetic_image — 8 passed.
  • cargo clippy -p victory-pe --all-targets -- -D warnings — passed, no warnings.
  • rustfmt --edition 2024 --check crates/victory-pe/tests/synthetic_image.rs — passed.
  • cargo xtask policy — passed (152 files OK).

One note: workspace-wide cargo fmt --all -- --check reports formatting differences in unrelated existing files. The new synthetic_image.rs file passes its individual formatting check.

No game data or external fixtures were used.

Thanks for the contribution!

**@⁠CesarLopesO** on GitHub · 2026-11-24 02:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/257#issuecomment-7119787293) Independent validation on Debian 13 (Trixie). I tested this PR locally with the following results: - `cargo test --locked -p victory-pe --test synthetic_image` — 8 passed. - `cargo clippy -p victory-pe --all-targets -- -D warnings` — passed, no warnings. - `rustfmt --edition 2024 --check crates/victory-pe/tests/synthetic_image.rs` — passed. - `cargo xtask policy` — passed (152 files OK). One note: workspace-wide `cargo fmt --all -- --check` reports formatting differences in unrelated existing files. The new `synthetic_image.rs` file passes its individual formatting check. No game data or external fixtures were used. Thanks for the contribution!
Author
Owner

@⁠SkippySteve on GitHub · 2026-11-24 02:27 UTC · original

superseded by #287 (combined PE/loader hermetic synthetic tests)

**@⁠SkippySteve** on GitHub · 2026-11-24 02:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/257#issuecomment-7120167497) superseded by #287 (combined PE/loader hermetic synthetic tests)

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