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

Closed
SkippySteve wants to merge 1 commit from upstream-pr/257 into main
SkippySteve commented 2026-11-24 01:52:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T01:52:59Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572802542 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/257). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T01:52:59Z. --- 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.
upstream-sync closed this pull request 2026-11-24 06:52:05 +00:00
CesarLopesO commented 2026-11-24 06:55:07 +00:00 (Migrated from github.com)

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


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!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119787293 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/257#issuecomment-7119787293). Originally posted by [CesarLopesO](https://github.com/CesarLopesO) on 2026-11-24T02:08:00Z. --- 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!
SkippySteve commented 2026-11-24 06:55:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T02:27:46Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120167497 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/257#issuecomment-7120167497). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T02:27:46Z. --- superseded by #287 (combined PE/loader hermetic synthetic tests)

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