PE: reject out-of-image TLS callback VAs in va_to_rva #2532
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!2532
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2532"
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?
@reeledMarek on GitHub · 2026-11-25 15:23 UTC · original
reeledMarek:fix/pe-tls-va-bounds→main· +36 −4 · 1 files · 1 commits · openProblem
victory_pe::image::va_to_rvaonly checked thatva - image_basefit inu32, never that the resulting RVA was< size_of_image.Because
victory-loadercalls parsedTlsInfo::callback_rvasdirectly as function pointers atbase + rva, a TLS callback VA in[image_base + size_of_image, image_base + 4 GiB)passedImageInfo::parseand caused an out-of-image jump.Fix
opt.size_of_image()intoparse_tlsandva_to_rva, filteringrva < size_of_image.Testing
rejects_tls_callback_outside_size_of_imageincrates/victory-pe/src/image.rs.cargo test -p victory-pe --locked rejects_tls_callback_outside_size_of_imageand Windows cross-clippy (-D warnings).@Marvisak on GitHub · 2026-11-25 15:53 UTC · original
Automated triage for the maintainers.
Recommended for a look.
va_to_rvain crates/victory-pe/src/image.rs now rejects RVAs at or pastSizeOfImage, soparse_tlsno longer accepts TLS callback (or callback array) VAs outside the image; these RVAs are called directly in victory-loader's windows.rs, and the check matches thesize_of_imagebound already applied to import slots. The new test uses the existingsynthetic_imagehelper (SizeOfImage 0x2000) and checks both the accepted and the rejected case. CI (clippy + tests on Windows): passing.Generated by Claude Code
@studiostephe on GitHub · 2026-11-25 17:05 UTC · original
va_to_rva(image.rs:434) only checks thatva - image_basefits in au32— never that the resulting RVA is belowsize_of_image.victory-loadercalls parsedTlsInfo::callback_rvasdirectly as function pointers atbase + rva(windows.rs:317), so a TLS callback VA in[image_base + size_of_image, image_base + 4 GiB)passesImageInfo::parseand causes an out-of-image jump.Pass
opt.size_of_image()throughparse_tlsand reject any TLS VA whose RVA is past the image (both the callback array pointer and each callback slot).Verified (native, M1 Mac, Rust 1.98.1):
cargo test -p victory-pe --locked— 34 passed; the 4 failures (parses_own_test_binary,rva_to_file_offset_maps_entry_point,rva_to_file_offset_rejects_offsets_past_4_gib,rejects_iat_outside_image) are pre-existing on unpatchedmain(theown_image()tests read the test binary, which fails in this environment) and are unrelated to this change.rejects_tls_callback_outside_size_of_imageandaccepts_tls_image_without_callbacksboth pass.rva >= size_of_imagecheck removed,rejects_tls_callback_outside_size_of_imagefails (the out-of-image callback is accepted), confirming the test exercises the fix.rustfmt --edition 2024 --checkclean;cargo clippy -p victory-pe --all-targets --locked— 0 warnings.Not covered: the fix is verified at the parse level (the RVA bound is enforced). I could not run the loader end-to-end (no Windows), so the out-of-image-jump scenario is proven by the parse rejection, not by a runtime test.
qwen3.8_27b running locally on an M1 Mac
shout out to Digital Debris Los Angeles
@fuzeofficlal on GitHub · 2026-11-26 00:51 UTC · original
Code review and Windows 11 verification at head
9e35b94dec37merged cleanly ontomain(63bcca43c6a0):crates/victory-pe/src/image.rs:416-440):va_to_rvarejects< ImageBaseunderflow viachecked_sub,> 4 GiBoverflow viau32::try_from, and>= SizeOfImage(includingImageBase + SizeOfImageandSizeOfImage == 0) via.filter(|&rva| rva < size_of_image).parse_tlsbreaks on the null terminator (if va == 0 { break; }) before invokingva_to_rva, andcallbacks_vais checked through bothva_to_rvaandsections.pe_data_at. Confirmedva_to_rvais private toimage.rswith only these two call sites, protectingvictory-loader/src/windows.rs:317from out-of-image callback pointers.cargo xtask policy:191 files ok;cargo clippy --locked -p victory-pe -p victory-loader --tests -- -D warnings: 0 warningsvictory-pe: 37/37 passed (includingrejects_tls_callback_outside_size_of_image)victory-loader: 35/35 unit + 4/4 integration passed.LGTM.
@fuzeofficlal on GitHub · 2026-11-26 13:18 UTC · original · approved these changes
Reviewed and verified
9e35b94dmerged locally ontoorigin/main(63bcca43) on Windows 11 x64 (Rust1.98.1MSVC; synthetic tests only, no game files).Verification
git merge-treeagainstorigin/main(63bcca43): clean.cargo xtask policy(PR head):182 files ok.cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings(default and--all-features, PR head and merged): 0 warnings.cargo test --locked -p victory-pe -p victory-loader—victory-pe37 passed, 0 failed (includingrejects_tls_callback_outside_size_of_image),victory-loader35 unit + 4 integration passed, 0 failed.cargo test --locked --release -p victory-pe— 37 passed, 0 failed.--release): verifiedva < image_base,va == 0,va == image_base,va == image_base + size_of_image - 1,va == image_base + size_of_image,va == image_base + (1 << 32), andsize_of_image == 0.Review Notes
rva < size_of_imageinva_to_rva(crates/victory-pe/src/image.rs:435-440) and passingopt.size_of_image()throughparse_tls(:194,:394-433) closes the out-of-image TLS callback pointer gap ahead ofvictory-loader's callback invocation, matching thesize_of_imagebound already enforced on import slots.parse_tlsbreaks on the0terminator before callingva_to_rva, andva_to_rvais private toimage.rswith only these two call sites, so legitimate PE images are unaffected.Looks good to merge.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.