Loader: fix thunk block overflow, capacity enforcement, flush errors, and leaks #1306

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

@⁠geiyiliyabumo on GitHub · 2026-11-24 17:17 UTC · original
geiyiliyabumo:test/loader-thunks-audit → main · +167 −7 · 1 files · 1 commits · open

Summary

Audits \crates/victory-loader/src/thunks.rs\ and fixes 4 bugs:

  • Prevents size multiplication overflow and enforces the exact requested slot count (including zero).
  • Propagates instruction-cache flush failures from \seal()\ instead of silently ignoring them.
  • Releases virtual memory reservations via \Drop\ for abandoned, empty, or failed thunk blocks while retaining process lifetime for successfully sealed stubs.
  • Adds 4 deterministic synthetic unit tests covering capacity, overflow rejection, x86_64 stub encoding/execution round-trip, and reservation release on drop.

Verification

  • \cargo test -p victory-loader --lib thunks\ ? 6 passed, 0 failed
  • \cargo clippy -p victory-loader --all-targets -- -D warnings\ ? clean
  • \cargo xtask policy\ ? 154 files ok

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 17:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1306) `geiyiliyabumo:test/loader-thunks-audit` → `main` · +167 −7 · 1 files · 1 commits · open ## Summary Audits \crates/victory-loader/src/thunks.rs\ and fixes 4 bugs: - Prevents size multiplication overflow and enforces the exact requested slot count (including zero). - Propagates instruction-cache flush failures from \seal()\ instead of silently ignoring them. - Releases virtual memory reservations via \Drop\ for abandoned, empty, or failed thunk blocks while retaining process lifetime for successfully sealed stubs. - Adds 4 deterministic synthetic unit tests covering capacity, overflow rejection, x86_64 stub encoding/execution round-trip, and reservation release on drop. ## Verification - \cargo test -p victory-loader --lib thunks\ ? 6 passed, 0 failed - \cargo clippy -p victory-loader --all-targets -- -D warnings\ ? clean - \cargo xtask policy\ ? 154 files ok *AI-assisted; synthetic tests only, no game files.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:26:59 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 02:34 UTC · original

Automated triage for the maintainers.

The four fixes in crates/victory-loader/src/thunks.rs do not address failures that can happen on main. ThunkBlock::new is called only from LoadedImage::bind_imports in windows.rs, behind if !unresolved.is_empty(). So the count is never zero, and count * 32 cannot overflow for an import list. On main, the page-rounded capacity only allows more slots than requested, never fewer, so emit cannot overrun. The new Drop frees memory only on error paths where bind_imports returns Err and the image is never run. On x64, FlushInstructionCache failing is not a realistic case. The stub-encoding test is reasonable on its own, but it checks the bytes the code already writes.

If you have a case where one of these paths is reached, please describe it and push a change; a small PR adding only the encoding/round-trip test would also be welcome. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label. No CI ran on this head.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 02:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1306#issuecomment-7150908355) <!-- victory-triage v1 head=29d78bae7044b6a395d0201575cad0bbafa260cf verdict=proposed-close at=2026-11-25T02:20:29Z --> Automated triage for the maintainers. The four fixes in `crates/victory-loader/src/thunks.rs` do not address failures that can happen on main. `ThunkBlock::new` is called only from `LoadedImage::bind_imports` in `windows.rs`, behind `if !unresolved.is_empty()`. So the count is never zero, and `count * 32` cannot overflow for an import list. On main, the page-rounded capacity only allows more slots than requested, never fewer, so `emit` cannot overrun. The new `Drop` frees memory only on error paths where `bind_imports` returns `Err` and the image is never run. On x64, `FlushInstructionCache` failing is not a realistic case. The stub-encoding test is reasonable on its own, but it checks the bytes the code already writes. If you have a case where one of these paths is reached, please describe it and push a change; a small PR adding only the encoding/round-trip test would also be welcome. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. No CI ran on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
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/1306/head:github-bot/gh-1306'
git switch 'github-bot/gh-1306'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1306'
git switch 'github-bot/gh-1306'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1306'
git switch 'github-bot/gh-1306'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1306'
git switch 'main'
git merge --squash 'github-bot/gh-1306'
git switch 'main'
git merge --ff-only 'github-bot/gh-1306'
git switch 'main'
git merge 'github-bot/gh-1306'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1306
No description provided.