Loader: fix 4 bounds and cleanup bugs in windows.rs with unit tests #1047

Open
opened 2026-11-26 04:18:17 +00:00 by github-bot · 2 comments
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 15:16 UTC · original

Summary

Fixes 4 real bounds-checking and cleanup bugs in crates/victory-loader/src/windows.rs (previously 0 unit tests) and adds 13 deterministic synthetic unit tests.

Because external PR creation is currently restricted (collaborators_only), the CI-green branch is ready on my fork for cherry-pick / review:

  • Branch: geiyiliyabumo/VIctory@test/loader-windows
  • Commit: geiyiliyabumo/VIctory@98b761b (based on main ffe310e)

Bugs Fixed (crates/victory-loader/src/windows.rs)

  1. Unchecked IAT writes: write_slots now validates rva + 8 <= size_of_image as a batch before any write.
  2. Module leak on TLS redirect failure: load now calls FreeLibrary when tls::redirect fails after LoadLibraryExW.
  3. Out-of-bounds TLS callbacks: callbacks with RVA 0 or >= size_of_image are now logged and skipped instead of executed.
  4. Out-of-image DllMain / entry point: guarded in both notify and spawn_main.

Verification (Windows 11 x64 MSVC)

  • rustfmt --edition 2024 --check crates/victory-loader/src/windows.rs: PASS
  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy -p victory-loader --all-targets --locked -- -D warnings (default + --features diagnostics): PASS (0 warnings)
  • cargo test -p victory-loader --locked -- windows::: 13 passed, 0 failed

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

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 15:16 UTC · [original](https://github.com/Marvisak/VIctory/issues/1047) ### Summary Fixes 4 real bounds-checking and cleanup bugs in `crates/victory-loader/src/windows.rs` (previously 0 unit tests) and adds 13 deterministic synthetic unit tests. Because external PR creation is currently restricted (`collaborators_only`), the CI-green branch is ready on my fork for cherry-pick / review: - **Branch**: `geiyiliyabumo/VIctory@test/loader-windows` - **Commit**: `geiyiliyabumo/VIctory@98b761b` (based on `main` `ffe310e`) ### Bugs Fixed (`crates/victory-loader/src/windows.rs`) 1. **Unchecked IAT writes**: `write_slots` now validates `rva + 8 <= size_of_image` as a batch before any write. 2. **Module leak on TLS redirect failure**: `load` now calls `FreeLibrary` when `tls::redirect` fails after `LoadLibraryExW`. 3. **Out-of-bounds TLS callbacks**: callbacks with RVA `0` or `>= size_of_image` are now logged and skipped instead of executed. 4. **Out-of-image `DllMain` / entry point**: guarded in both `notify` and `spawn_main`. ### Verification (Windows 11 x64 MSVC) - `rustfmt --edition 2024 --check crates/victory-loader/src/windows.rs`: **PASS** - `cargo xtask policy`: **PASS** (`154 files ok`) - `cargo clippy -p victory-loader --all-targets --locked -- -D warnings` (default + `--features diagnostics`): **PASS** (0 warnings) - `cargo test -p victory-loader --locked -- windows::`: **13 passed, 0 failed** *AI-assisted; synthetic tests only, no game files.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:18:17 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:52 UTC · original · edited 2026-11-25 09:58 UTC

Automated triage for the maintainers.

Correction to the earlier note: the TLS-redirect part of this is open as PR #1201 ("free mapped module on TLS redirect error and add windows.rs unit tests"), which links this issue.

One of the four cases holds on current main (940d32f). In load (crates/victory-loader/src/windows.rs), an error from tls::redirect returns through ? after LoadLibraryExW mapped the image. LoadedImage has no Drop, and FreeLibrary is called only in unload, so the module stays mapped. The impact is small, because that error ends the run anyway. #1201 fixes it.

The other three cases (IAT slots in write_slots, out-of-image TLS callbacks, out-of-image entry points) still read as hardening. write_slots relies on the parser yielding only slots inside the image, and nothing so far shows the parser accepting an image that breaks this. The Windows 11 run above confirms that the branch builds and its tests pass. It does not show these cases can happen. A synthetic image (no game files) that the parser accepts and that reaches one of them would settle it.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/1047#issuecomment-7155244262) · edited 2026-11-25 09:58 UTC <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T09:07:24Z at=2026-11-25T09:50:38Z --> Automated triage for the maintainers. Correction to the earlier note: the TLS-redirect part of this is open as PR #1201 ("free mapped module on TLS redirect error and add windows.rs unit tests"), which links this issue. One of the four cases holds on current `main` (`940d32f`). In `load` (`crates/victory-loader/src/windows.rs`), an error from `tls::redirect` returns through `?` after `LoadLibraryExW` mapped the image. `LoadedImage` has no `Drop`, and `FreeLibrary` is called only in `unload`, so the module stays mapped. The impact is small, because that error ends the run anyway. #1201 fixes it. The other three cases (IAT slots in `write_slots`, out-of-image TLS callbacks, out-of-image entry points) still read as hardening. `write_slots` relies on the parser yielding only slots inside the image, and nothing so far shows the parser accepting an image that breaks this. The Windows 11 run above confirms that the branch builds and its tests pass. It does not show these cases can happen. A synthetic image (no game files) that the parser accepts and that reaches one of them would settle it. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠StExpeditus on GitHub · 2026-11-25 09:07 UTC · original

Validated the fork branch on Windows 11 Pro 26200 (Intel Core i5-14600K, Rust 1.98.1 MSVC), commit 5edb22b:

  • cargo test -p victory-loader --locked -> 43 passed, 0 failed (the 13 windows:: tests included).
  • cargo clippy -p victory-loader --all-targets --locked -- -D warnings -> clean.
  • cargo fmt -p victory-loader -- --check flags crash.rs:71, which the branch inherits from its base (ffe310e); the same drift exists on current main under this toolchain, and windows.rs itself is fmt-clean.
  • The fix applies cleanly on current main (940d32f6): the only victory-loader delta is the 413-line change to windows.rs itself, no unrelated churn.

No game files used; synthetic tests only. The fix looks ready to cherry-pick.

**@⁠StExpeditus** on GitHub · 2026-11-25 09:07 UTC · [original](https://github.com/Marvisak/VIctory/issues/1047#issuecomment-7157905062) Validated the fork branch on Windows 11 Pro 26200 (Intel Core i5-14600K, Rust 1.98.1 MSVC), commit `5edb22b`: - `cargo test -p victory-loader --locked` -> **43 passed, 0 failed** (the 13 `windows::` tests included). - `cargo clippy -p victory-loader --all-targets --locked -- -D warnings` -> **clean**. - `cargo fmt -p victory-loader -- --check` flags `crash.rs:71`, which the branch inherits from its base (`ffe310e`); the same drift exists on current main under this toolchain, and `windows.rs` itself is fmt-clean. - The fix applies cleanly on current main (`940d32f6`): the only `victory-loader` delta is the 413-line change to `windows.rs` itself, no unrelated churn. No game files used; synthetic tests only. The fix looks ready to cherry-pick.
This discussion has been locked. Commenting is limited to contributors.
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#1047
No description provided.