Skip to content

PE: tests for delay-import parsing (names, ordinals, IAT bounds) - #2731

Open
Vedoxdev123 wants to merge 1 commit into
Marvisak:mainfrom
Vedoxdev123:pe/delay-import-tests
Open

Vedoxdev123 wants to merge 1 commit into
Marvisak:mainfrom
Vedoxdev123:pe/delay-import-tests

Conversation

@Vedoxdev123

Copy link
Copy Markdown

parse_delay_imports in victory-pe had no unit test. Delay imports were only reached through the loader's load_probe fixture and the census's synthetic ImageInfo, so a regression in how the parser reads them (or in the IAT bounds check it shares with normal imports) would not fail a victory-pe test.

What is in it

  • crates/victory-pe/src/image.rs: four tests on a synthetic image, built on the existing synthetic_image helper. No change to the parser.
    • delay_imports_list_names_and_ordinals_with_their_iat_slots: the DLL name, a name import (hint 5), an ordinal import, and the IAT slot RVA of each; normal imports stay empty.
    • an_image_without_a_delay_load_directory_has_no_delay_imports.
    • a_delay_iat_ending_at_the_end_of_the_image_is_accepted: the last slot ends exactly at SizeOfImage.
    • a_delay_iat_running_past_the_image_is_rejected: one byte further, and an IAT at 0xFFFF_FFF8, give PeError::Malformed.

Tested

  • Windows 11, Ryzen 5 5600X, on main 13f91ca.
  • cargo test -p victory-pe: 40 passed (36 before).
  • Checked the new tests can fail: with the bound in entries() changed from end <= size_of_image to end <= u32::MAX, a_delay_iat_running_past_the_image_is_rejected fails. Reverted.
  • cargo clippy -p victory-pe --all-targets --locked -- -D warnings: clean. rustfmt --edition 2024 --check: clean. cargo xtask policy: 184 files ok.

Not tested

  • Only victory-pe was run for this change. A full workspace run on this base (GPU and shader crates excluded) passed with no failures.
  • Delay-import descriptors with the old VA-based attribute (attribute bit 0 clear) are not covered; the parser is object's there.

AI use

  • Claude Code (Claude Sonnet 5.5) found the gap, wrote the tests and ran the checks; I reviewed them.

No game data used.

🤖 Generated with Claude Code

parse_delay_imports had no unit test in victory-pe; delay imports were
only reached through the loader's load_probe fixture and the census's
synthetic ImageInfo. Add four tests on a synthetic image:

- a delay-load directory lists its DLL, a name import (with hint) and an
  ordinal import, with the IAT slot RVA of each, and adds nothing to the
  normal imports;
- an image without the directory has no delay imports;
- an IAT whose last slot ends exactly at SizeOfImage is accepted;
- one byte further, and an IAT at the 4 GiB limit, are refused as malformed.

Tests only; no change to the parser.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cloph-dsp

Copy link
Copy Markdown

Independent Windows verification (AI-assisted, Hy4 flash). Rust/cargo 1.100.0, MSVC, no game data, no GPU.

$env:CARGO_BUILD_JOBS=2
cargo test --locked -p victory-pe --lib delay --quiet
# running 4 tests ... test result: ok. 4 passed; 0 failed; 0 measured; 36 filtered out
cargo test --locked -p victory-pe --lib --quiet
# running 40 tests ... test result: ok. 40 passed; 0 failed; 0 measured; 0 filtered out

Negative control: the four new test names are absent from origin/main in crates/victory-pe/src/image.rs (git grep -c returned no matches), so the tests are genuinely introduced by this PR. No blocking findings; synthetic byte buffers only.

@XeNS1

XeNS1 commented Nov 25, 2026

Copy link
Copy Markdown

Independent native Linux verification of 694baa30780f4634d03d2f831bf11cb5b20ae652 on 13f91ca, plus integration with the section-RVA coverage in #2740 (f0d5342). Rust 1.100.0, x86-64, two build jobs; no game files or GPU execution.

  • Exact PR head: all four delay-import tests pass; the portable victory-pe suite has 36 passed, 0 failed. Four unchanged tests requiring the host executable to be a Windows PE were excluded by name.
  • Applied PE tests: cover section RVA boundaries on every host #2740 without conflicts in a detached validation worktree: 41 passed, 0 failed, with only three Windows-host tests excluded (its fourth is now portable). Strict --all-targets --all-features Clippy passes for both the original head and the combination; combined staged asset policy passes.
  • Three mutations in a separate snapshot of the exact PR head are detected: changing the image bound from <= to < fails the exact-end acceptance test; allowing every non-overflowing u32 end fails the out-of-image rejection test; changing IAT stride from 8 to 4 fails three new tests. The unmodified snapshot passes all four delay tests.

Commands for the original head:

cargo test -p victory-pe --locked --offline -- --skip parses_own_test_binary --skip rva_to_file_offset_maps_entry_point --skip rva_to_file_offset_rejects_offsets_past_4_gib --skip rejects_iat_outside_image
cargo clippy -p victory-pe --all-targets --all-features --locked --offline -- -D warnings

The combination uses the same commands with the overflow-test exclusion removed.

No blocking findings in this scope. Legacy VA-based delay descriptors and actual Windows loading were not exercised. This complements the existing Windows report; no competing implementation. AI-assisted: OpenAI Codex.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Independent Windows 11 verification and review of 694baa3 (on 13f91ca):

Verification (rustc 1.98.1 MSVC)

Review Notes

  • Clean, 100% synthetic tests covering named/ordinal delay imports, missing directory, exact SizeOfImage upper bound, 1-byte overshoot, and u32 overflow (0xFFFF_FFF8). Ready to merge.

@kotekompotek

Copy link
Copy Markdown

Good coverage of the delay-import path: name ordinals, ordinal-bit entries, iat_slot_rva mapping, and the bounds case. Synthetic fixture builds the descriptor table correctly (RVA attributes bit, terminator descriptor).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Adds four unit tests for parse_delay_imports in crates/victory-pe/src/image.rs on a synthetic image built from the existing synthetic_image helper: names and ordinals with their IAT slot RVAs, no delay directory, an IAT ending exactly at SizeOfImage, and IATs running past the image or past 4 GiB. I checked that the fixture's descriptor layout (RVA attribute, name table, terminator) is valid and that the expected bounds are the correct PE behaviour rather than just what the code does; no parser change and no game data. CI passes. This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

@futurepro62

Copy link
Copy Markdown

NVIDIA full-suite run, to go with the reports above by XeNS1, cloph-dsp, fuzeofficlal, since none of them names a GPU run. Tested exact head 694baa3 (on its base 13f91ca).

Tested

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified locally on Windows 11 x64:

  • cargo test -p victory-pe -- --test-threads=1: 40 passed, 0 failed (including all 4 new delay-import tests: delay_imports_list_names_and_ordinals_with_their_iat_slots, an_image_without_a_delay_load_directory_has_no_delay_imports, a_delay_iat_ending_at_the_end_of_the_image_is_accepted, and a_delay_iat_running_past_the_image_is_rejected).
  • cargo clippy -p victory-pe --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants