PE: refuse an import address table inside the headers #1559
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1560"
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 default-cybe on 2026-11-24T19:10:37Z.
What
ImageInfo::parsenow refuses an import whose IAT slot starts belowSizeOfHeaders. This covers normal and delay-load imports. Before,entries()(crates/victory-pe/src/image.rs) checked only the top end: the slot had to end at or belowSizeOfImage.Why
victory-loaderbinds every slot itself.bind_importscollects eachiat_slot_rvafromimportsanddelay_imports.write_slots(crates/victory-loader/src/windows.rs) then callsVirtualProtect(PAGE_READWRITE)onbase + rvaand writes 8 bytes there. Its SAFETY comment relies on "the parser only yields slots inside the image". An image withFirstThunk(or a delayImportAddressTableRVA) belowSizeOfHeaderspassed that check, so the loader would overwrite the image's own mapped headers with host pointers. This follows from readingbind_importsandwrite_slots; no such image was loaded (see Not tested).Linkers place the IAT in a section, never in the headers, so well-formed images are unaffected. The bound is
rva >= SizeOfHeaders, written from the PE format and VIctory's own code. The bytes betweenSizeOfHeadersand the first section are accepted as before.Change
parse_imports,parse_delay_importsandentriestakesize_of_headersnext tosize_of_image.Malformederror, now worded "IAT at .. overlaps the headers or runs outside the image".refuses_iat_in_headers: a synthetic in-memory PE32+ (the existingsynthetic_imagehelper,SizeOfHeaders0x200) with one import, built once as a normal import and once as a delay-load import. An IAT at 0x80 or 0x1F8 is refused. An IAT at 0x200 or 0x1080 still parses, with that slot RVA.Tested
Windows 11 x64, Rust 1.98.1 (the pinned toolchain), synthetic inputs only, on
mainffe310eplus this commit.mainplus only the new test module), the new test fails:IAT at 0x80 (delay: false) was accepted. With the loop narrowed to[true]in a scratch copy, the delay-load case fails the same way:IAT at 0x80 (delay: true) was accepted.cargo test -p victory-pe --lib iat: 2 passed, 0 failed.cargo test --workspace: 343 passed, 0 failed, 6 ignored.cargo xtask policy: asset policy: 154 files ok.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(the CI command): clean.cargo fmt --check -p victory-pe: clean.Not tested
AI use
Written with Conclave (model
cliproxy/claude-opus-5-5), which also ran the commands listed under Tested.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:20:58Z.
Review: APPROVED
IAT slots must now lie past
SizeOfHeadersas well as inside the image — the loader writes every slot, so an IAT overlapping the headers would corrupt them. Applied to both normal and delay-load imports via the sharedentries()helper, with the error message updated. The newrefuses_iat_in_headerstest covers both import kinds at 0x80/0x1F8 (rejected) and 0x200/0x1080 (accepted) and passes on macOS.Note:
cargo test -p victory-peon macOS shows 4 pre-existing failures inimage::tests(they parse the Mach-O test binary as a PE — present on unmodified main, unrelated to this PR); the other 4 tests pass including the new one.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:30:47Z.
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-pe/src/image.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-25T01:32:58Z.
Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head
db470dfapplied cleanly onto currentmainccfb029.cargo test -p victory-pe --locked: the new testrefuses_iat_in_headerspasses on Linux. The 4imagetests that parse the test binary as a PE fail (expected on Linux — they fail identically on main).cargo clippy -p victory-pe --all-targets --all-features --locked -- -D warnings: clean.Not tested: Windows MSVC build, the title itself. AI-assisted.
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.