Loader: write IAT slots as bytes, so an IAT at an odd RVA is not UB (debug builds aborted at load) #260

Open
sharan104 wants to merge 1 commit from upstream-pr/260 into main
sharan104 commented 2026-11-26 13:33:26 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by sharan104 on 2026-11-26T13:33:26Z.


windows.rs write_slots patched IAT slots with write_volatile through a *mut u64. Its SAFETY comment said the slots are "8-byte aligned by the PE format", but the format doesn't require that, and the parser doesn't check it. A title image whose IAT sits at an odd RVA is undefined behaviour, and a debug build aborts at load with "ptr::write_volatile requires that the pointer argument is aligned".

Fix: the slot is written as [u8; 8] (little-endian), still volatile, so no alignment is assumed. The SAFETY comment now says so.

Test: an_unaligned_iat_slot_is_written writes two misaligned slots, one of them across a page boundary, into read-only pages, the same as an image's import table. Before the fix it aborted; after it, it passes (10 runs out of 10).

Results:

  • cargo test -p victory-loader --locked passes.
  • Clippy -D warnings is clean, apart from descriptor_sites.rs:277, which is already failing on main and which #169 fixes.

🤖 Generated with Claude Code

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6627778873 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/260). Originally posted by [sharan104](https://github.com/sharan104) on 2026-11-26T13:33:26Z. --- `windows.rs` `write_slots` patched IAT slots with `write_volatile` through a `*mut u64`. Its SAFETY comment said the slots are "8-byte aligned by the PE format", but the format doesn't require that, and the parser doesn't check it. A title image whose IAT sits at an odd RVA is undefined behaviour, and a debug build aborts at load with "ptr::write_volatile requires that the pointer argument is aligned". **Fix:** the slot is written as `[u8; 8]` (little-endian), still volatile, so no alignment is assumed. The SAFETY comment now says so. **Test:** `an_unaligned_iat_slot_is_written` writes two misaligned slots, one of them across a page boundary, into read-only pages, the same as an image's import table. Before the fix it aborted; after it, it passes (10 runs out of 10). **Results:** - `cargo test -p victory-loader --locked` passes. - Clippy `-D warnings` is clean, apart from `descriptor_sites.rs:277`, which is already failing on `main` and which #169 fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/260:upstream-pr/260'
git switch 'upstream-pr/260'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/260'
git switch 'upstream-pr/260'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/260'
git switch 'upstream-pr/260'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/260'
git switch 'main'
git merge --squash 'upstream-pr/260'
git switch 'main'
git merge --ff-only 'upstream-pr/260'
git switch 'main'
git merge 'upstream-pr/260'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
avatarmanz/VIctory-7900XTX!260
No description provided.