Loader: never pass NULL address hint to VirtualAlloc in tls::near #3066
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3066
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3066"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Dukestar69 on GitHub · 2026-11-26 06:02 UTC · original
Dukestar69:fix/tls-near-null-hint→main· +23 −3 · 1 files · 1 commits · closed without mergingSummary
Prevents
tls::nearfrom passing aNULL(0) address hint toVirtualAllocand uses checked arithmetic for upper candidate addresses so allocated TLS thunk pages are guaranteed to stay within ±2 GiBrel32reach of the image.Why
In
crates/victory-loader/src/tls.rs,nearsearched downward withbase.checked_sub((k + 1) * GRANULE). Wheneverbaseis a multiple ofGRANULE(0x1_0000) and<= 1 GiB,(k + 1) * GRANULE == baseyieldsSome(0). Passing0(NULL) aslpAddresstellsVirtualAllocto ignore the hint and allocate anywhere in the 64-bit address space (e.g.,0x1d068de0000forbase = 0x10000), whichpatchthen silently truncates viarel as i32into an invalidcall rel32target.Filtering out
0(.filter(|&h| h != 0)) and usingchecked_add/checked_next_multiple_offor the upper hints avoids both theNULL-hint escape and high-address overflow.Verification
tls::tests::near_never_uses_null_hint_outside_rel32_reach:63bcca4(allocated at 0x1d068de0000, outside rel32 reach of 0x10000).cargo test -p victory-loader -- --test-threads=1: 40 passed, 0 failed (36 unit + 4 integration).cargo clippy -p victory-loader --all-targets -- -D warnings: clean.rustfmt --edition 2024 --check crates/victory-loader/src/tls.rs: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@Marvisak on GitHub · 2026-11-26 06:18 UTC · original
Automated triage for the maintainers.
Proposed close: guard for a case that does not occur. In
crates/victory-loader/src/tls.rs(near), the search alternates between a hint below the image and one above it, and returns at the first free page. For the downward hint to reach 0, the title image would need to sit at or below 1 GiB, with every 64 KiB granule below it taken, and the same number of granules just above its end taken too. The only caller istls::redirect, with the image the OS loaded. The new test only reaches the NULL hint by passingbase = 0x10000, where the very first downward hint is 0, which is not an address an image is loaded at. Thechecked_addandchecked_next_multiple_ofon the upward hint likewise guard against overflowing 64-bit user space, which cannot happen.This PR will be closed in 48 hours unless the author pushes a change, or a maintainer removes the label. A report of the title's image actually landing that low would change this.
CI: no checks ran on this head.
Generated by Claude Code
@Dukestar69 on GitHub · 2026-11-26 06:45 UTC · original
Fair point from triage — a real 64-bit PE image will not sit at or below 1 GiB with the entire +1 GiB range above it occupied. Closing to keep the queue clean. AI-assisted (Gemini 4 Neon).
Pull request closed