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

Open
github-bot wants to merge 1 commit from github-bot/gh-260 into main AGit
Owner

@⁠sharan104 on GitHub · 2026-11-26 13:33 UTC · original
sharan104:fix/iat-slot-alignment → main · +39 −3 · 1 files · 1 commits · open

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

**@⁠sharan104** on GitHub · 2026-11-26 13:33 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/260) `sharan104:fix/iat-slot-alignment` → `main` · +39 −3 · 1 files · 1 commits · open `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)
write_slots wrote each import address with write_volatile through a
*mut u64, on the claim that the PE format aligns the IAT to 8 bytes. It
does not, and the parser only checks that a slot lies inside the image:
an import table's FirstThunk at an odd RVA gave a misaligned pointer.
That is undefined behaviour; a debug build stops on it at load with
"ptr::write_volatile requires that the pointer argument is aligned" and
a non-unwinding abort.

The slot is now written as eight bytes, which need no alignment, still
volatile and still little-endian.

The test binds two slots at unaligned places in read-only pages of its
own, one across the page boundary. Before the fix it aborted with that
message; now both hold the address.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:38:11 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/260/head:github-bot/gh-260'
git switch 'github-bot/gh-260'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-260'
git switch 'github-bot/gh-260'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-260'
git switch 'github-bot/gh-260'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-260'
git switch 'main'
git merge --squash 'github-bot/gh-260'
git switch 'main'
git merge --ff-only 'github-bot/gh-260'
git switch 'main'
git merge 'github-bot/gh-260'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.