Loader: fix 4 bounds/overflow bugs in tls.rs and stacks.rs with unit tests #938
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#938
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@geiyiliyabumo on GitHub · 2026-11-24 14:21 UTC · original
Summary
Fixes 4 real bugs in
crates/victory-loader/src/tls.rsandcrates/victory-loader/src/stacks.rs, and expands unit tests (tls::1 -> 14,stacks::1 -> 2).Because external PR creation is currently restricted (
collaborators_only), the CI-green branch is ready on my fork for cherry-pick / review:geiyiliyabumo/VIctory@test/loader-tls-and-stacksgeiyiliyabumo/VIctory@02ea74c(based onmainffe310e)Bugs Fixed
crates/victory-loader/src/tls.rs:AddressOfIndexagainstsize_of_image(previously followed unchecked, allowing reads past the image and writing0over an out-of-imageu32).index * 8against debug overflow for image-supplied indices nearu32::MAX.virtual_sizeexecutable sections instead of callingVirtualProtect(..., 0, ...)(OS error 87) and aborting redirect.crates/victory-loader/src/stacks.rs:4. Extracted
delays()to reject non-finite / out-of-rangeVICTORY_STACKSvalues (inf,NaN,1e300) instead of panicking inDuration::from_secs_f64.Verification (Windows 11 x64 MSVC)
rustfmt --edition 2024 --check: PASScargo 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 -- tls::(14/14 PASS) &--features diagnostics -- stacks::(2/2 PASS)AI-assisted; synthetic tests only, no game files.
@DaniiL35 on GitHub · 2026-11-24 14:41 UTC · original
Independent Verification Review: geiyiliyabumo:test/loader-tls-and-stacks (
02ea74c)Audited the PE TLS directory validation, section protection bounds, and stack schedule parsing:
1. Correctness of Bug Fixes
A. TLS Directory & Index Bounds (
crates/victory-loader/src/tls.rs)AddressOfIndexpointing outside the image mapping (or near the end of address space). Previously,redirectperformed an unchecked dereference and write (index_at.write(0)), potentially corrupting host memory or crashing with an access violation.directory + TLS64_ADDRESS_OF_INDEX + size_of::<usize>() <= sizeprevents running past image boundaries when reading the directory entry.VirtualProtectstrictly rejectsdwSize == 0withERROR_INVALID_PARAMETER(87). Skipping sections wherevirtual_size == 0avoids aborting redirects on images containing empty placeholder sections (e.g. metadata or discardable debug headers).index <= MAX_INDEXprevents arithmetic overflow when calculating thunk offsets (index * 8).B. Robust Float Duration Parsing (
crates/victory-loader/src/stacks.rs)dump_stacks_on_schedule,Duration::from_secs_f64unconditionally panics iftisNaN,inf, or exceeds the maximum representableDuration(~1e19seconds).delays()properly filters witht.is_finite()andDuration::try_from_secs_f64(t.max(0.0)).ok().2. Minor Hardening Recommendation (Integer Overflow Edge Case)
In
crates/victory-loader/src/tls.rs:If
index_atcontains an arbitrary 64-bit value whereat >= baseandat - base > usize::MAX - 4, evaluatingat - base + size_of::<u32>()will overflow and wrap around in release builds (or panic in debug builds).To be completely watertight against arbitrary pointer values, consider bounds-checking without addition:
(or via
(at - base).checked_add(size_of::<u32>()).map_or(true, |end| end > size)).3. Test Fixture & Policy Compliance
Syntheticimage fixture intls::testscleanly allocates a mock PE image in private memory withVirtualAlloc, tests redirects, verifies slot calculations againsttls_array(), and frees viaDrop.Solid catch and ready to merge.
@Marvisak on GitHub · 2026-11-25 06:59 UTC · original
Automated triage for the maintainers.
Part of this is already on
main:crates/victory-loader/src/stacks.rsnow parses theVICTORY_STACKStimes withDuration::try_from_secs_f64(PR #221), soinf/NaNno longer panic.tls::redirectincrates/victory-loader/src/tls.rsstill follows the TLS directory and index without bounds checks and callsVirtualProtecton every executable section, including ones with a zerovirtual_size; the image is the title's own, so the bounds checks guard malformed input rather than a case seen in the title. The branch is open as PR #1192, where review continues.Generated by Claude Code