Skip to content

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

Closed
SkippySteve wants to merge 1 commit into
Marvisak:mainfrom
SkippySteve:SkippySteve/victory-pr-own-next7
Closed

SkippySteve wants to merge 1 commit into
Marvisak:mainfrom
SkippySteve:SkippySteve/victory-pr-own-next7

Conversation

@SkippySteve

Copy link
Copy Markdown

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.
@CesarLopesO

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants