fix(loader): preserve protection regions when binding unaligned imports #1111
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1111"
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 divyeshganta on 2026-11-24T15:48:38Z.
Related to #923. Import binding now supports unaligned IAT slots and restores each crossed memory region’s protection, including cleanup after partial setup failure. Adds synthetic Windows regressions. Patch by DocBlack89 (
5f8800dd93).Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T16:01:20Z.
Review: APPROVED
Tested head
5f8800d(fast-forward onmainffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):cargo test -p victory-loader: 25 unit + 2load_probe+ 1title_dllspassed, 0 failed (includingiat_binding_preserves_each_crossed_page_protection,iat_slot_writes_accept_every_byte_alignment, andiat_binding_failure_restores_earlier_pages_without_writing)cargo clippy -p victory-loader --all-targets: 0 warningscargo xtask policy: okSolid loader safety fix preserving page protections across unaligned/cross-page IAT slot writes. Approving.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Kal0s-design on 2026-11-24T16:31:50Z.
Independent check of
5f8800d, merged locally ontomainffe310e(fast-forward). Windows 11, MSVC, Rust 1.98.1 as pinned. It adds to DenRakEiw's run on the same head with a repeat count and a check of the old behaviour.cargo test -p victory-loader --locked: 25 unit + 2load_probe+ 1title_dllspassed, 0 failed. The lib suite was run 10 more times: 10/10 green.cargo clippy -p victory-loader --all-targets --locked -- -D warnings, with and without--all-features: clean.--lockedholds with the newWin32_System_SystemInformationfeature.main. Instead I replayedmain'swrite_slotssequence in a scratch test that is not part of the PR:VirtualProtect(slot, 8, PAGE_READWRITE), a write, thenVirtualProtect(slot, 8, old), with the slot straddling a PAGE_READONLY page and a PAGE_EXECUTE_READ page. After the sequence the second page reads back as PAGE_READONLY, not PAGE_EXECUTE_READ, 3 runs out of 3: the singleoldvalue restores only the first page's protection. This is what the per-region restore in this PR fixes.Not covered: that case needs a slot that is not 8-aligned, which a normal linker output does not produce, so this is hardening against malformed images; nothing was run against a real title.
AI-assisted: yes. Every number above is from my own runs.
Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T18:01:46Z.
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
5f8800d:cargo test -p victory-loaderpasses, 28 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:26:10Z.
Automated triage for the maintainers.
Needs work.
LoadedImage::write_slots(crates/victory-loader/src/windows.rs) now writes IAT slots withwrite_unaligned. The newwrite_protected_iat_slotwalks each memory region the slot crosses withVirtualQuery, makes each one writable, and restores all of them, including after a partial failure. The code reads correctly and the tests check it, but it handles a case real images don't produce. An 8-byte-aligned slot can't cross a page boundary, so only an unaligned slot can span two regions, and linker-built PE32+ images align their import tables. The bug shown in the comments needs a straddling slot, which the tests build by hand.What would make this mergeable: a short change that checks the one real assumption. The loader or
victory-peparser could reject (or report) an IAT slot that isn't 8-byte aligned, and the comment "8-byte aligned by the PE format" would then be enforced instead of assumed. If you know of a real image with unaligned IAT slots, please name it. That would justify the multi-region handling as it is.The
Win32_System_SystemInformationfeature is only used by the tests.CI: not run.
Generated by Claude Code
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.