PE: reject null IAT RVAs in non-empty import descriptors #2741

Open
github-bot wants to merge 1 commit from github-bot/gh-2741 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:24 UTC · original
fuzeofficlal:fix/pe-reject-null-iat-rva → main · +115 −8 · 1 files · 1 commits · open

Summary

Reject iat_rva == 0 in crates/victory-pe/src/image.rs::entries whenever an import or delay-import descriptor contains at least one thunk:

  • parse_imports and parse_delay_imports pass FirstThunk and ImportAddressTableRVA as iat_rva into entries().
  • Previously, entries() only verified iat_rva + offset + 8 <= size_of_image, so a non-empty descriptor with iat_rva == 0 passed validation with iat_slot_rva = 0 (pointing at the DOS MZ header), causing downstream victory-loader/src/prepare.rs to panic on rva_to_file_offset(0).unwrap() (or runtime patching to target image_base + 0).
  • Returning Err(PeError::Malformed(...)) inside the thunk loop rejects null IAT RVAs for both regular and delay imports while leaving empty descriptors unaffected.

Tests

Added rejects_null_iat_for_regular_imports and rejects_null_iat_for_delay_imports in crates/victory-pe/src/image.rs.

Verification

  • cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings: 0 warnings.
  • cargo test --locked -p victory-pe: 38 passed, 0 failed.
  • cargo test --locked -p victory-loader --lib: 34 passed, 0 failed.
  • cargo xtask policy: 184 files ok.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2741) `fuzeofficlal:fix/pe-reject-null-iat-rva` → `main` · +115 −8 · 1 files · 1 commits · open ## Summary Reject `iat_rva == 0` in `crates/victory-pe/src/image.rs::entries` whenever an import or delay-import descriptor contains at least one thunk: - `parse_imports` and `parse_delay_imports` pass `FirstThunk` and `ImportAddressTableRVA` as `iat_rva` into `entries()`. - Previously, `entries()` only verified `iat_rva + offset + 8 <= size_of_image`, so a non-empty descriptor with `iat_rva == 0` passed validation with `iat_slot_rva = 0` (pointing at the DOS `MZ` header), causing downstream `victory-loader/src/prepare.rs` to panic on `rva_to_file_offset(0).unwrap()` (or runtime patching to target `image_base + 0`). - Returning `Err(PeError::Malformed(...))` inside the thunk loop rejects null IAT RVAs for both regular and delay imports while leaving empty descriptors unaffected. ## Tests Added `rejects_null_iat_for_regular_imports` and `rejects_null_iat_for_delay_imports` in `crates/victory-pe/src/image.rs`. ## Verification - `cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings`: 0 warnings. - `cargo test --locked -p victory-pe`: **38 passed, 0 failed**. - `cargo test --locked -p victory-loader --lib`: **34 passed, 0 failed**. - `cargo xtask policy`: 184 files ok.
Import entries previously checked only that each 8-byte IAT slot ended within SizeOfImage, accepting null (RVA 0), header RVAs (such as 0x40), and gaps between sections, which would cause victory-loader/src/windows.rs to patch the image headers instead of an IAT slot. Check that every 8-byte IAT slot lies within one file-backed section as well as within SizeOfImage, and test null regular/delay IAT RVAs and a non-zero header IAT RVA.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:11 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:05 UTC · original

Right place for the check: inside the thunk loop it fires only when a descriptor actually has entries, so empty/terminator descriptors with IAT=0 still parse. Covering both regular (FirstThunk) and delay (ImportAddressTableRVA) imports in tests is thorough.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2741#issuecomment-7173188806) Right place for the check: inside the thunk loop it fires only when a descriptor actually has entries, so empty/terminator descriptors with IAT=0 still parse. Covering both regular (FirstThunk) and delay (ImportAddressTableRVA) imports in tests is thorough.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:15 UTC · original

Independent WARP/CPU verification for head e9df3bdcfd0c5811db1e86831308ba888cf3f268 against origin/main 13f91caee2. State check at start and again before posting: open, non-draft, mergeable, head unchanged; no prior oni-swr comment.

Environment: Windows 11 x64, Rust 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1, Windows SDK dxil.dll 10.0.26100.0 (file version 1.8.2502.11). VICTORY_WARP=1 and VICTORY_D3D12_WARP=1 set (WARP only, no physical GPU); no game files. CARGO_TARGET_DIR=D:\victory-warp-2741-target. Tested commit: the PR head itself, which is exactly one commit on top of origin/main (merge-base = origin/main, so no temporary merge was needed).

Commands/results:

  • Baseline (origin/main): cargo test --locked -p victory-pe — 36 passed, 0 failed, 0 ignored. cargo clippy --locked -p victory-pe --all-targets -- -D warnings — pass.
  • PR: cargo test --locked -p victory-pe --lib rejects_null_iat — 2/2 passed. cargo test --locked -p victory-pe — 38 passed (+2), 0 failed, 0 ignored. cargo clippy --locked -p victory-pe --all-targets -- -D warnings — pass.
  • Negative control: kept both new tests, disabled the production check (if iat_rva == 0 -> if false && iat_rva == 0); rejects_null_iat_for_regular_imports and rejects_null_iat_for_delay_imports both FAILED (0 passed, 2 failed). Restored, tree clean.

Review: no blocker found. The check sits inside the while let Some(thunk) loop, so descriptors with no thunks are unaffected and only a non-empty table with a null IAT RVA is rejected; it is shared by regular and delay imports, and both have a test (the regular one mutates the image's own import descriptor, the delay one builds a synthetic image). The error is PeError::Malformed, consistent with the neighbouring checks.

Not tested: physical GPU, retail title/game behavior, release build (debug profile only).

AI disclosure: Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 20:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2741#issuecomment-7173406579) Independent WARP/CPU verification for head e9df3bdcfd0c5811db1e86831308ba888cf3f268 against origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca. State check at start and again before posting: open, non-draft, mergeable, head unchanged; no prior oni-swr comment. Environment: Windows 11 x64, Rust 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1, Windows SDK dxil.dll 10.0.26100.0 (file version 1.8.2502.11). `VICTORY_WARP=1` and `VICTORY_D3D12_WARP=1` set (WARP only, no physical GPU); no game files. `CARGO_TARGET_DIR=D:\victory-warp-2741-target`. Tested commit: the PR head itself, which is exactly one commit on top of `origin/main` (merge-base = `origin/main`, so no temporary merge was needed). Commands/results: - Baseline (origin/main): `cargo test --locked -p victory-pe` — 36 passed, 0 failed, 0 ignored. `cargo clippy --locked -p victory-pe --all-targets -- -D warnings` — pass. - PR: `cargo test --locked -p victory-pe --lib rejects_null_iat` — 2/2 passed. `cargo test --locked -p victory-pe` — 38 passed (+2), 0 failed, 0 ignored. `cargo clippy --locked -p victory-pe --all-targets -- -D warnings` — pass. - Negative control: kept both new tests, disabled the production check (`if iat_rva == 0` -> `if false && iat_rva == 0`); `rejects_null_iat_for_regular_imports` and `rejects_null_iat_for_delay_imports` both FAILED (0 passed, 2 failed). Restored, tree clean. Review: no blocker found. The check sits inside the `while let Some(thunk)` loop, so descriptors with no thunks are unaffected and only a non-empty table with a null IAT RVA is rejected; it is shared by regular and delay imports, and both have a test (the regular one mutates the image's own import descriptor, the delay one builds a synthetic image). The error is `PeError::Malformed`, consistent with the neighbouring checks. Not tested: physical GPU, retail title/game behavior, release build (debug profile only). AI disclosure: Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:24 UTC · original · edited 2026-11-26 02:17 UTC

Automated triage for the maintainers.

Merge candidate (recommending a look, not an approval). Thanks for the update. entries in crates/victory-pe/src/image.rs now requires every 8-byte IAT slot to lie inside one file-backed section (iat_slot_in_section, within min(VirtualSize, SizeOfRawData)) as well as inside SizeOfImage, for both regular and delay imports, instead of special-casing RVA 0. That rejects a null IAT and one pointing into the headers or a section gap, and the three tests (null regular, header RVA 0x40, null delay) cover it; the description now points at the load-path patching in victory-loader/src/windows.rs. The rule is stricter than "inside the image": an IAT placed in a section's uninitialised tail would now be refused, which matches how linkers lay out import tables but is worth knowing. It merges cleanly and CI check is passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2741#issuecomment-7177507085) · edited 2026-11-26 02:17 UTC <!-- victory-triage v1 head=ed0b242c34db8b2f45f3b08d0cc133c08e3c2863 verdict=merge-candidate at=2026-11-26T02:17:20Z --> Automated triage for the maintainers. **Merge candidate** (recommending a look, not an approval). Thanks for the update. `entries` in `crates/victory-pe/src/image.rs` now requires every 8-byte IAT slot to lie inside one file-backed section (`iat_slot_in_section`, within `min(VirtualSize, SizeOfRawData)`) as well as inside `SizeOfImage`, for both regular and delay imports, instead of special-casing RVA 0. That rejects a null IAT and one pointing into the headers or a section gap, and the three tests (null regular, header RVA 0x40, null delay) cover it; the description now points at the load-path patching in `victory-loader/src/windows.rs`. The rule is stricter than "inside the image": an IAT placed in a section's uninitialised tail would now be refused, which matches how linkers lay out import tables but is worth knowing. It merges cleanly and CI `check` is passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:33 UTC · original

Rebased onto origin/main (63bcca43) and updated in ed0b242c per triage feedback:

  • Replaced the iat_rva == 0 special case in entries (crates/victory-pe/src/image.rs) with iat_slot_in_section(sections, rva) verifying that the entire 8-byte IAT slot [rva, rva + 8) lies inside a single file-backed section (with non-overflowing file offset) as well as within size_of_image.
  • Kept rejects_null_iat_for_regular_imports and rejects_null_iat_for_delay_imports, and added rejects_header_iat_for_regular_imports (FirstThunk = 0x40).
  • Corrected the commit description to reference load-path patching in victory-loader/src/windows.rs rather than the test-only unwrap() in prepare.rs.

Verified on Windows 11: cargo test --locked -p victory-pe -p victory-loader (victory-pe 39/39, victory-loader 35/35 unit + 4/4 integration), cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings, and cargo xtask policy (191 files ok).

**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2741#issuecomment-7177738839) Rebased onto `origin/main` (`63bcca43`) and updated in `ed0b242c` per triage feedback: - Replaced the `iat_rva == 0` special case in `entries` (`crates/victory-pe/src/image.rs`) with `iat_slot_in_section(sections, rva)` verifying that the entire 8-byte IAT slot `[rva, rva + 8)` lies inside a single file-backed section (with non-overflowing file offset) as well as within `size_of_image`. - Kept `rejects_null_iat_for_regular_imports` and `rejects_null_iat_for_delay_imports`, and added `rejects_header_iat_for_regular_imports` (`FirstThunk = 0x40`). - Corrected the commit description to reference load-path patching in `victory-loader/src/windows.rs` rather than the test-only `unwrap()` in `prepare.rs`. Verified on Windows 11: `cargo test --locked -p victory-pe -p victory-loader` (`victory-pe` 39/39, `victory-loader` 35/35 unit + 4/4 integration), `cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings`, and `cargo xtask policy` (`191 files ok`).
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 13:07 UTC · original

NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head ed0b242 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 869 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: rejects_null_iat_for_regular_imports, rejects_header_iat_for_regular_imports, rejects_null_iat_for_delay_imports.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

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.
**@⁠futurepro62** on GitHub · 2026-11-26 13:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2741#issuecomment-7192910386) NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head `ed0b242` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **869 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `rejects_null_iat_for_regular_imports`, `rejects_header_iat_for_regular_imports`, `rejects_null_iat_for_delay_imports`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **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.
Author
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 21:12 UTC · original · reviewed

Verified on Linux (Rust 1.99.0)

Branch: current main (13f91ca) + this PR (fast-forward, no conflicts with main).

  • cargo test --locked -p victory-pe: rejects_null_iat_for_delay_imports passes. With the new iat_rva == 0 check removed, it fails at the final matches! (image.rs:595). So the synthetic delay-import test pins the fix.
  • rejects_null_iat_for_regular_imports cannot run on Linux. It uses own_image() (the test executable), which is ELF there. It fails on Linux the same way the 4 existing own_image tests do on main, so I only checked it by reading.
  • cargo clippy --locked --target x86_64-pc-windows-msvc -p victory-pe --all-targets -- -D warnings: clean, same as main.

Findings

  1. Overlaps #1560, which covers this case and more. #1560 ("PE: refuse an import address table inside the headers", open, one approval, currently conflicting) rejects any IAT slot below SizeOfHeaders for both regular and delay imports. RVA 0 is one such case. This PR rejects only exactly 0. I changed the delay test to set ImportAddressTableRVA = 8 instead of 0, and ImageInfo::parse accepts it (the test's matches! fails at image.rs:600). The slot then still lands in the DOS header, and the loader's write_slots would write a host pointer there. Suggestion: check rva < size_of_headers as #1560 does, and coordinate with its author so only one of the two lands.

  2. The description's panic path is test code. The rva_to_file_offset(..).unwrap() it cites is at crates/victory-loader/src/prepare.rs:238, inside #[cfg(test)] mod tests (line 176). The production consequence is the one in crates/victory-loader/src/windows.rs:245: the slot is queued and later written at image_base + 0. Worth correcting in the description, because that write is the stronger reason to merge.

Not verified

  • Windows-only paths: the own_image-based test, and loader behaviour with such an image.

Reviewed with Claude Code.

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/2741#pullrequestreview-6065049935) · **reviewed** ### Verified on Linux (Rust 1.99.0) Branch: current `main` (13f91ca) + this PR (fast-forward, no conflicts with main). - `cargo test --locked -p victory-pe`: `rejects_null_iat_for_delay_imports` passes. With the new `iat_rva == 0` check removed, it fails at the final `matches!` (image.rs:595). So the synthetic delay-import test pins the fix. - `rejects_null_iat_for_regular_imports` cannot run on Linux. It uses `own_image()` (the test executable), which is ELF there. It fails on Linux the same way the 4 existing `own_image` tests do on main, so I only checked it by reading. - `cargo clippy --locked --target x86_64-pc-windows-msvc -p victory-pe --all-targets -- -D warnings`: clean, same as main. ### Findings 1. **Overlaps #1560, which covers this case and more.** #1560 ("PE: refuse an import address table inside the headers", open, one approval, currently conflicting) rejects any IAT slot below `SizeOfHeaders` for both regular and delay imports. RVA 0 is one such case. This PR rejects only exactly 0. I changed the delay test to set `ImportAddressTableRVA = 8` instead of 0, and `ImageInfo::parse` accepts it (the test's `matches!` fails at image.rs:600). The slot then still lands in the DOS header, and the loader's `write_slots` would write a host pointer there. Suggestion: check `rva < size_of_headers` as #1560 does, and coordinate with its author so only one of the two lands. 2. **The description's panic path is test code.** The `rva_to_file_offset(..).unwrap()` it cites is at `crates/victory-loader/src/prepare.rs:238`, inside `#[cfg(test)] mod tests` (line 176). The production consequence is the one in `crates/victory-loader/src/windows.rs:245`: the slot is queued and later written at `image_base + 0`. Worth correcting in the description, because that write is the stronger reason to merge. ### Not verified - Windows-only paths: the `own_image`-based test, and loader behaviour with such an image. Reviewed with Claude Code.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 13:37 UTC · original

Independent Windows/MSVC data point for head ed0b242 (adds to the existing WARP and NVIDIA reports):

  • cargo test --locked -p victory-pe --lib -- image::tests::rejects_null_iat_for_delay_imports --exact — 1 passed, 0 failed (38 filtered).
  • git diff --check origin/main HEAD — clean.

Used a worktree-local CARGO_TARGET_DIR and the hand-written synthetic PE bytes in the test; the two own_image() tests were not the focus of this check. Windows 11, Rust 1.100.0/MSVC, CPU-only, GPU/driver N/A. AI-assisted (Hy4 flash). No game assets, extracted shaders, logs or DRM material used.

**@⁠cloph-dsp** on GitHub · 2026-11-26 13:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2741#issuecomment-7193614272) Independent Windows/MSVC data point for head `ed0b242` (adds to the existing WARP and NVIDIA reports): - `cargo test --locked -p victory-pe --lib -- image::tests::rejects_null_iat_for_delay_imports --exact` — 1 passed, 0 failed (38 filtered). - `git diff --check origin/main HEAD` — clean. Used a worktree-local `CARGO_TARGET_DIR` and the hand-written synthetic PE bytes in the test; the two `own_image()` tests were not the focus of this check. Windows 11, Rust 1.100.0/MSVC, CPU-only, GPU/driver N/A. AI-assisted (Hy4 flash). No game assets, extracted shaders, logs or DRM material used.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2741/head:github-bot/gh-2741'
git switch 'github-bot/gh-2741'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2741'
git switch 'github-bot/gh-2741'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2741'
git switch 'github-bot/gh-2741'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2741'
git switch 'main'
git merge --squash 'github-bot/gh-2741'
git switch 'main'
git merge --ff-only 'github-bot/gh-2741'
git switch 'main'
git merge 'github-bot/gh-2741'
git push origin 'main'
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!2741
No description provided.