PE: reject null IAT RVAs in non-empty import descriptors #2739
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2741"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:24:34Z.
Summary
Reject
iat_rva == 0incrates/victory-pe/src/image.rs::entrieswhenever an import or delay-import descriptor contains at least one thunk:parse_importsandparse_delay_importspassFirstThunkandImportAddressTableRVAasiat_rvaintoentries().entries()only verifiediat_rva + offset + 8 <= size_of_image, so a non-empty descriptor withiat_rva == 0passed validation withiat_slot_rva = 0(pointing at the DOSMZheader), causing downstreamvictory-loader/src/prepare.rsto panic onrva_to_file_offset(0).unwrap()(or runtime patching to targetimage_base + 0).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_importsandrejects_null_iat_for_delay_importsincrates/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.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:05:57Z.
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.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T20:15:33Z.
Independent WARP/CPU verification for head
e9df3bdcfdagainst origin/main13f91caee2. 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=1andVICTORY_D3D12_WARP=1set (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 oforigin/main(merge-base =origin/main, so no temporary merge was needed).Commands/results:
cargo test --locked -p victory-pe— 36 passed, 0 failed, 0 ignored.cargo clippy --locked -p victory-pe --all-targets -- -D warnings— pass.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.if iat_rva == 0->if false && iat_rva == 0);rejects_null_iat_for_regular_importsandrejects_null_iat_for_delay_importsboth 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 isPeError::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).
Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-11-25T21:12:09Z.
Review: COMMENTED
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_importspasses. With the newiat_rva == 0check removed, it fails at the finalmatches!(image.rs:595). So the synthetic delay-import test pins the fix.rejects_null_iat_for_regular_importscannot run on Linux. It usesown_image()(the test executable), which is ELF there. It fails on Linux the same way the 4 existingown_imagetests 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
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
SizeOfHeadersfor both regular and delay imports. RVA 0 is one such case. This PR rejects only exactly 0. I changed the delay test to setImportAddressTableRVA = 8instead of 0, andImageInfo::parseaccepts it (the test'smatches!fails at image.rs:600). The slot then still lands in the DOS header, and the loader'swrite_slotswould write a host pointer there. Suggestion: checkrva < size_of_headersas #1560 does, and coordinate with its author so only one of the two lands.The description's panic path is test code. The
rva_to_file_offset(..).unwrap()it cites is atcrates/victory-loader/src/prepare.rs:238, inside#[cfg(test)] mod tests(line 176). The production consequence is the one incrates/victory-loader/src/windows.rs:245: the slot is queued and later written atimage_base + 0. Worth correcting in the description, because that write is the stronger reason to merge.Not verified
own_image-based test, and loader behaviour with such an image.Reviewed with Claude Code.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:24:01Z.
Automated triage for the maintainers.
Merge candidate (recommending a look, not an approval). Thanks for the update.
entriesincrates/victory-pe/src/image.rsnow requires every 8-byte IAT slot to lie inside one file-backed section (iat_slot_in_section, withinmin(VirtualSize, SizeOfRawData)) as well as insideSizeOfImage, 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 invictory-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 CIcheckis passing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:33:54Z.
Rebased onto
origin/main(63bcca43) and updated ined0b242cper triage feedback:iat_rva == 0special case inentries(crates/victory-pe/src/image.rs) withiat_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 withinsize_of_image.rejects_null_iat_for_regular_importsandrejects_null_iat_for_delay_imports, and addedrejects_header_iat_for_regular_imports(FirstThunk = 0x40).victory-loader/src/windows.rsrather than the test-onlyunwrap()inprepare.rs.Verified on Windows 11:
cargo test --locked -p victory-pe -p victory-loader(victory-pe39/39,victory-loader35/35 unit + 4/4 integration),cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings, andcargo xtask policy(191 files ok).Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T13:07:36Z.
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 base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo 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.rejects_null_iat_for_regular_imports,rejects_header_iat_for_regular_imports,rejects_null_iat_for_delay_imports.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#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_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T13:37:43Z.
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_DIRand the hand-written synthetic PE bytes in the test; the twoown_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.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T01:31:18Z.
Review: APPROVED
LGTM — verified on Windows:
iat_slot_in_section) cleanly rejects null and header IAT RVAs for both regular and delay-load importscargo test -p victory-pepassed (39/39, includingrejects_null_iat_for_regular_imports,rejects_header_iat_for_regular_imports, andrejects_null_iat_for_delay_imports)cargo clippy -p victory-pe --all-targets -- -D warningspassed with 0 warningscargo xtask policypassed (191 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.