Loader: skip empty executable sections in tls::redirect and add tls.rs unit tests #1192

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

@⁠geiyiliyabumo on GitHub · 2026-11-24 16:23 UTC · original
geiyiliyabumo:test/loader-tls-and-stacks → main · +312 −1 · 1 files · 1 commits · open

Summary

Closes #938

Full verification details and change notes are documented in #938 (commit 02ea74c, based on main ffe310e).

 crates/victory-loader/src/stacks.rs |  50 ++++-
 crates/victory-loader/src/tls.rs    | 383 +++++++++++++++++++++++++++++++++++-
 2 files changed, 421 insertions(+), 12 deletions(-)

Verification (Windows 11 x64 MSVC)

  • rustfmt --edition 2024 --check on edited files: PASS
  • cargo xtask policy: PASS (zero game files/data)
  • cargo clippy --all-targets --locked -- -D warnings (default + --features diagnostics where applicable): PASS
  • Targeted & crate unit/GPU tests: PASS

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

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 16:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1192) `geiyiliyabumo:test/loader-tls-and-stacks` → `main` · +312 −1 · 1 files · 1 commits · open ### Summary Closes #938 Full verification details and change notes are documented in #938 (commit `02ea74c`, based on `main` `ffe310e`). ```text crates/victory-loader/src/stacks.rs | 50 ++++- crates/victory-loader/src/tls.rs | 383 +++++++++++++++++++++++++++++++++++- 2 files changed, 421 insertions(+), 12 deletions(-) ``` ### Verification (Windows 11 x64 MSVC) - `rustfmt --edition 2024 --check` on edited files: **PASS** - `cargo xtask policy`: **PASS** (zero game files/data) - `cargo clippy --all-targets --locked -- -D warnings` (default + `--features diagnostics` where applicable): **PASS** - Targeted & crate unit/GPU tests: **PASS** *AI-assisted; synthetic tests only, no game files.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:07 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-11-24 16:27 UTC · original

Independent check of 02ea74c, merged locally onto main ffe310e (merge was clean). Windows 11, MSVC, Rust 1.98.1 as pinned.

  • cargo test -p victory-loader --locked: lib 35 passed, 0 failed; 2 + 1 integration tests pass. The lib suite was run 15 more times: 15/15 green.
  • cargo clippy -p victory-loader --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • Sensitivity: I put this PR's tls.rs test module on top of main's production code (nothing else changed). 4 tests fail on 3 of 3 runs: a_directory_outside_the_image_is_an_error, an_index_no_loader_assigns_is_an_error, an_index_outside_the_image_is_not_written, an_empty_executable_section_does_not_stop_the_rest. All pass with the PR's code.

Not covered: the stacks.rs change (delays is a new function, so its test cannot run against main; I only ran it on the PR); nothing was run against a real title.

AI-assisted: yes. Every number above is from my own runs.

**@⁠Kal0s-design** on GitHub · 2026-11-24 16:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1192#issuecomment-7137695632) Independent check of `02ea74c`, merged locally onto `main` `ffe310e` (merge was clean). Windows 11, MSVC, Rust 1.98.1 as pinned. - `cargo test -p victory-loader --locked`: lib 35 passed, 0 failed; 2 + 1 integration tests pass. The lib suite was run 15 more times: 15/15 green. - `cargo clippy -p victory-loader --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - Sensitivity: I put this PR's `tls.rs` test module on top of `main`'s production code (nothing else changed). 4 tests fail on 3 of 3 runs: `a_directory_outside_the_image_is_an_error`, `an_index_no_loader_assigns_is_an_error`, `an_index_outside_the_image_is_not_written`, `an_empty_executable_section_does_not_stop_the_rest`. All pass with the PR's code. Not covered: the `stacks.rs` change (`delays` is a new function, so its test cannot run against `main`; I only ran it on the PR); nothing was run against a real title. AI-assisted: yes. Every number above is from my own runs.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:00 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 02ea74c: cargo test -p victory-loader passes, 38 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1192#issuecomment-7140020524) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 02ea74c: `cargo test -p victory-loader` passes, 38 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:18 UTC · original · edited 2026-11-25 08:16 UTC

Automated triage for the maintainers.

Merge candidate. Update after your latest push (ee9defc): the point from the last triage is addressed. tls::redirect (crates/victory-loader/src/tls.rs) now takes the section length as virtual_size, or file_size when that is 0, matching how victory_pe maps sections (crates/victory-pe/src/image.rs), and skips a section only when both are 0. The new test an_executable_section_with_zero_virtual_size_uses_its_file_size covers the raw-data-with-VirtualSize-0 case, and the SIB nit in other_nine_byte_windows_are_left_alone is fixed ([rsi], no displacement).

The rest is unit tests for patch, thunks, near and redirect on a synthetic image, which check the right things (per-register call targets, near-misses, thunk bytes, the slot the patched load returns). Only tls.rs changes; no dependencies.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1192#issuecomment-7149408800) · edited 2026-11-25 08:16 UTC <!-- victory-triage v1 head=ee9defcd54900931353b92e5aa50d9c68d5642e4 verdict=merge-candidate at=2026-11-25T08:16:10Z --> Automated triage for the maintainers. **Merge candidate.** Update after your latest push (`ee9defc`): the point from the last triage is addressed. `tls::redirect` (`crates/victory-loader/src/tls.rs`) now takes the section length as `virtual_size`, or `file_size` when that is 0, matching how `victory_pe` maps sections (`crates/victory-pe/src/image.rs`), and skips a section only when both are 0. The new test `an_executable_section_with_zero_virtual_size_uses_its_file_size` covers the raw-data-with-`VirtualSize`-0 case, and the SIB nit in `other_nine_byte_windows_are_left_alone` is fixed (`[rsi], no displacement`). The rest is unit tests for `patch`, `thunks`, `near` and `redirect` on a synthetic image, which check the right things (per-register call targets, near-misses, thunk bytes, the slot the patched load returns). Only `tls.rs` changes; no dependencies. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-25 01:55 UTC · original

Rebased cleanly onto \main\ (\ccfb029). \cargo test -p victory-loader --locked\ (51 passed, 0 failed), \cargo test -p victory-loader --locked --features diagnostics --lib stacks::tests\ (3 passed, 0 failed), \cargo clippy -p victory-loader --all-targets --locked -- -D warnings, and \cargo xtask policy\ all pass.

**@⁠geiyiliyabumo** on GitHub · 2026-11-25 01:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1192#issuecomment-7150114986) Rebased cleanly onto \main\ (\ccfb029\). \cargo test -p victory-loader --locked\ (51 passed, 0 failed), \cargo test -p victory-loader --locked --features diagnostics --lib stacks::tests\ (3 passed, 0 failed), \cargo clippy -p victory-loader --all-targets --locked -- -D warnings\, and \cargo xtask policy\ all pass.
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-25 04:00 UTC · original

Updated per triage feedback: reverted \stacks.rs\ completely back to \main\ and dropped the three redundant
edirect\ range guards and their guard-only tests, keeping only the empty-executable-section (\len == 0) skip hardening and the \patch/\ hunks\ unit tests in \ ls.rs. Rebased onto \main\ (\940d32f); \cargo test -p victory-loader --locked\ (48 passed, 0 failed), \cargo clippy -p victory-loader --all-targets --locked -- -D warnings, and \cargo xtask policy\ all pass.

**@⁠geiyiliyabumo** on GitHub · 2026-11-25 04:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1192#issuecomment-7152445111) Updated per triage feedback: reverted \stacks.rs\ completely back to \main\ and dropped the three redundant \ edirect\ range guards and their guard-only tests, keeping only the empty-executable-section (\len == 0\) skip hardening and the \patch\/\ hunks\ unit tests in \ ls.rs\. Rebased onto \main\ (\940d32f\); \cargo test -p victory-loader --locked\ (48 passed, 0 failed), \cargo clippy -p victory-loader --all-targets --locked -- -D warnings\, and \cargo xtask policy\ all pass.
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-25 07:55 UTC · original

Updated \ ls::redirect\ per triage feedback (head $sha): fall back to \ ile_size\ when \ irtual_size == 0\ (matching \ ictory_pe::image::rva_to_file_offset) and skip only when both are 0, added a synthetic regression test for \ irtual_size == 0\ with non-zero \ ile_size, and fixed the \

**@⁠geiyiliyabumo** on GitHub · 2026-11-25 07:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1192#issuecomment-7156411377) Updated \ ls::redirect\ per triage feedback (head \$sha\): fall back to \ ile_size\ when \ irtual_size == 0\ (matching \ ictory_pe::image::rva_to_file_offset\) and skip only when both are 0, added a synthetic regression test for \ irtual_size == 0\ with non-zero \ ile_size\, and fixed the \
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:25 UTC · original

Code review and Windows 11 verification at head ee9defcd5490 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-loader/src/tls.rs:51-61, 182-530):
    • Skipping sections whose effective length (virtual_size if non-zero else file_size) is 0 cleanly avoids VirtualProtect(..., 0, ...) failing with ERROR_INVALID_PARAMETER and aborting static TLS redirection.
    • All 10 new synthetic VirtualAlloc tests thoroughly cover real relocated execution across GPRs, negative 9-byte windows, overlapping matches, thunk layout, 1 GiB near bounds, virtual_size == 0 fallback, and empty executable sections.
    • Note for maintainers: #188 also introduces #[cfg(test)] mod tests at the bottom of tls.rs (minor text-only merge conflict; production changes are orthogonal and compose cleanly).
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-loader --tests -- -D warnings: 0 warnings
    • cargo test --locked -p victory-loader: 50/50 passed (46 unit including all 10 tls::tests + 4 integration).

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1192#issuecomment-7179762754) Code review and Windows 11 verification at head `ee9defcd5490` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-loader/src/tls.rs:51-61, 182-530`)**: - Skipping sections whose effective length (`virtual_size` if non-zero else `file_size`) is `0` cleanly avoids `VirtualProtect(..., 0, ...)` failing with `ERROR_INVALID_PARAMETER` and aborting static TLS redirection. - All 10 new synthetic `VirtualAlloc` tests thoroughly cover real relocated execution across GPRs, negative 9-byte windows, overlapping matches, thunk layout, 1 GiB `near` bounds, `virtual_size == 0` fallback, and empty executable sections. - Note for maintainers: `#188` also introduces `#[cfg(test)] mod tests` at the bottom of `tls.rs` (minor text-only merge conflict; production changes are orthogonal and compose cleanly). - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-loader --tests -- -D warnings`: 0 warnings - `cargo test --locked -p victory-loader`: **50/50 passed** (46 unit including all 10 `tls::tests` + 4 integration). LGTM.
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/1192/head:github-bot/gh-1192'
git switch 'github-bot/gh-1192'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1192'
git switch 'github-bot/gh-1192'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1192'
git switch 'github-bot/gh-1192'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1192'
git switch 'main'
git merge --squash 'github-bot/gh-1192'
git switch 'main'
git merge --ff-only 'github-bot/gh-1192'
git switch 'main'
git merge 'github-bot/gh-1192'
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!1192
No description provided.