PE: refuse an import address table inside the headers #1560
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1560
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@default-cybe on GitHub · 2026-11-24 19:10 UTC · original
default-cybe:fix/pe-refuse-iat-in-headers→main· +85 −8 · 1 files · 1 commits · openWhat
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.@Marvisak on GitHub · 2026-11-25 01:30 UTC · original
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
@Headache3318 on GitHub · 2026-11-25 01:32 UTC · original
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
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.