Repository navigation
Conversation
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-pe— 10 passed, 0 failed (includingrva_to_file_offset_maps_headers,tls_directory_and_callbacks_in_headers, andbounds_size_of_headers_by_the_file)cargo clippy -p victory-pe --all-targets— 0 warningscargo xtask policy— ok
Clean PE header RVA mapping with file-length bounds clamping and TLS directory/callback reading from headers. Looks good.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-pe --locked → 6 passed, 4 failed. The 4 failures are PRE-EXISTING on main on macOS/Linux (image::tests parse the test binary as a PE; it is Mach-O/ELF there — they need #[cfg(windows)] or a fixture; unrelated to this PR). The PR's own new tests all pass: rva_to_file_offset_maps_headers, tls_directory_and_callbacks_in_headers, bounds_size_of_headers_by_the_file, unused_export_slots_are_not_exports, rejects_garbage_without_panicking.
PE header RVAs are now mapped through file_data_at and TLS data is read from the headers — exactly the kind of loader prerequisite the HLE side needs.
|
Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head
Not tested: Windows MSVC build, the title itself. AI-assisted. |
|
Automated triage for the maintainers. The change in Generated by Claude Code |
The headers occupy RVA 0..SizeOfHeaders and are stored one-to-one at the start of the file, but ImageInfo only mapped section RVAs. A TLS directory or callback array in the headers failed with "outside of sections", and image preparation could not patch it either. Store SizeOfHeaders (rejecting a declared region past the end of the file, which the OS could not map), map header RVAs in rva_to_file_offset, and read the TLS directory and its callback array from the headers or the sections. The tests build header-backed TLS data by hand.
0b7a13c to
ae83bc6
Compare
|
@Marvisak Rebased onto Re-ran on Windows 11 x64, Rust 1.98.1 MSVC:
Unrelated to this PR, on this machine: |
AI-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.