PE: map header RVAs and read TLS data from the headers #1639
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!1639
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1639"
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?
@sandivd on GitHub · 2026-11-24 20:17 UTC · original
sandivd:pe-header-rva→main· +105 −7 · 2 files · 1 commits · openAI-assisted.
Problem
ImageInfomapped only section RVAs. The PE headers occupy RVA0..SizeOfHeadersand are stored one-to-one at the start of the file, so a data directory that points there is valid, but:ImageInfo::rva_to_file_offsetreturnedNonefor every RVA belowSizeOfHeaders, sopreparecould not patch a header-backed TLS directory (TLS directory is not file-backed).parse_tlsread both the TLS directory and its callback array throughSectionTable::pe_data_at, which searches sections only, and failed withTLS directory outside of sections.Fix
SizeOfHeadersinImageInfoand reject an image whose declared header region is larger than the file (the OS could not map that either).rva < SizeOfHeadersto the same file offset inrva_to_file_offset.file_data_at).ImageInfoliteral in thecensustest helper for the new field.This does not change callback termination or count rules; #324 and #1456 touch those lines, this change does not.
Verification
Rebased onto
ccfb029. Ran on Windows 11 x64, Rust 1.98.1,x86_64-pc-windows-msvc:cargo test -p victory-pe --locked: 39 passed (3 new: header mapping boundaries, TLS directory and callbacks in the headers,SizeOfHeadersbounded by the file).cargo clippy -p victory-pe --all-targets --all-features --locked -- -D warnings: clean.cargo clippy --workspace --all-targets --locked -- -D warningsand the--all-featuresvariant: clean.cargo test -p victory-loader --locked: 38 passed.cargo test --workspace --locked --exclude victory-shader --exclude victory-gpu: 313 passed, 5 ignored.cargo xtask policy: 182 files ok.cargo fmt -p victory-pe -- --checkandcargo fmt -p victory -- --check: clean.Two packages have failures on this machine that reproduce on unmodified
ccfb029:victory-gpu: 139 passed, 2 failed (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views).victory-shader: threeemit::testsabort withSTATUS_ACCESS_VIOLATION.victory-gpuandvictory-shaderdo not depend onvictory-pe.Scope
This is spec correctness, not a title failure reproduced here: a scan of 14,106 PE32+ images on this machine found no TLS, import, export or delay-import directory inside the headers (two
bound_importdirectories were). No game files were used; the tests build their TLS structures by hand.@Headache3318 on GitHub · 2026-11-25 01:32 UTC · original
Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head
0b7a13capplied cleanly onto currentmainccfb029.cargo test -p victory-pe --locked: 6 passed, 4 failed. The 4 failures are theimagetests that parse the test binary as a PE (expected on Linux — they fail identically on main). All 3 new tests pass on Linux:rva_to_file_offset_maps_headers,tls_directory_and_callbacks_in_headers,bounds_size_of_headers_by_the_file.cargo clippy -p victory-pe --all-targets --all-features --locked -- -D warnings: clean.Not tested: Windows MSVC build, the title itself. AI-assisted.
@Marvisak on GitHub · 2026-11-25 01:32 UTC · original · edited 2026-11-25 02:28 UTC
Automated triage for the maintainers.
The change in
crates/victory-pe/src/image.rsis consistent with the PE format:rva_to_file_offsetmaps RVAs belowSizeOfHeadersone-to-one, andparse_tlsreads the TLS directory and callback array through the newfile_data_at. The tests are synthetic and correct. But the description says this fixes no observed failure: a scan of 14,106 images found no TLS directory in the headers, and the title is not affected. It also adds a new way forImageInfo::parseto refuse an image (SizeOfHeaderslarger than the file). Changes to the loader need to be worth it for the images VIctory actually loads. What would change the verdict is an image the project loads (the title or one of the runtime DLLs it maps) whose TLS or another directory sits in the headers. Without one, a maintainer may prefer not to take the extra rejection path.Generated by Claude Code
@sandivd on GitHub · 2026-11-25 01:43 UTC · original
@Marvisak Rebased onto
ccfb029. The conflict was #219's section-bounds validation inparseand #555's export changes plus the newImageInfoliteral inapps/victory/src/census.rs, which now passessize_of_headers: 0. Both sides are kept; no behavior from those PRs changed.Re-ran on Windows 11 x64, Rust 1.98.1 MSVC:
cargo test -p victory-pe --locked: 39 passedcargo test -p victory-loader --locked: 38 passedcargo test --workspace --locked --exclude victory-shader --exclude victory-gpu: 313 passed, 5 ignoredcargo xtask policy: 182 files okcargo fmt -p victory-pe -- --checkandcargo fmt -p victory -- --check: cleanUnrelated to this PR, on this machine:
victory-gpuhas 2 failures andvictory-shaderaborts on 3emit::tests; both reproduce on unmodifiedccfb029.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.