pe: bound intake section spans by VirtualSize #754

Merged
FZNull merged 2 commits from upstream-pr/760 into main 2026-11-23 02:02:05 +00:00
FZNull commented 2026-11-23 01:22:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by FZNull on 2026-11-23T01:22:19Z.


Problem

tools/intake_exe.py bounded RVA placement and the TLS callback slot count by SizeOfRawData. A section whose Misc.VirtualSize exceeds its SizeOfRawData maps a zero-filled tail, and the Windows loader treats the section span as Misc.VirtualSize (tools/pe_map.cpp:95). A TLS directory or a callback-table terminator placed in that tail was rejected as unmapped or truncated, and the slot count stopped at the raw end.

Reproduction against the source-built intake_forward_caller.exe (.data: VirtualAddress 0xc000, Misc_VirtualSize 0x2b9, SizeOfRawData 0x200) with the TLS directory at RVA 0xc200:

Section: .data VA= 0xc000 VSize= 0x2b9 RawSize= 0x200
pe.get_data(tail_rva, 40) len: 0
ValueError: Unmapped or unsuitable RVA 0xc200

Change

  • section_for() and the TLS callback slot bound use Misc_VirtualSize (falling back to SizeOfRawData when it is zero, clamped to SizeOfImage), matching the loader.
  • read_rva() reads the file-backed prefix and zero-fills the rest of a request from the uninitialized virtual tail; a short file-backed prefix still raises Truncated data at RVA ....

One behavior, no unrelated changes.

Test

tests/intake/check.py gains check_virtual_tail_tls(). It extends the last section's VirtualSize past its raw data so the tail exists under either linker layout (Debug and Release lay the fixtures out differently), then checks:

  • a table terminated by the tail's implicit zero slot parses as one callback;
  • a TLS directory wholly inside the tail parses as an empty directory;
  • a directory crossing from raw data into the tail parses the same way;
  • negative control: a directory that leaves the section's virtual span is still rejected (Unmapped or unsuitable RVA ...);
  • negative control: the same table is still rejected as unterminated when VirtualSize stops claiming the tail.

The new test fails on main (Unterminated TLS callback table or inspection limit reached) and passes with the fix, on both dev and release.

Verification

Environment: Windows 11, Python 3.13.12 (out/pe-env, pefile 2024.8.26), MSVC 19.50.35726, Windows SDK 10.0.26100.0, CMake 4.5.1 + Ninja.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R 'static_exe_intake|conditional_import_paths|bundled_export_forwarders'
# 3/3 passed, 100%, exit 0

cmake --preset release
cmake --build --preset release
ctest --preset release --no-tests=error -R '^static_exe_intake$'
# 1/1 passed, 100%, exit 0

out\pe-env\Scripts\python.exe -B tests/intake/paths_check.py
# exit 0

Before the fix the issue reproduction exited 1 with ValueError: Unmapped or unsuitable RVA 0xc200; after the fix it exits 0 and the intake report lists the parsed TLS callbacks. This is fixture evidence for the loader-bound behavior, not full-game startup evidence.

Fixes #744

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6550341472 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/760). Originally posted by [FZNull](https://github.com/FZNull) on 2026-11-23T01:22:19Z. --- ## Problem `tools/intake_exe.py` bounded RVA placement and the TLS callback slot count by `SizeOfRawData`. A section whose `Misc.VirtualSize` exceeds its `SizeOfRawData` maps a zero-filled tail, and the Windows loader treats the section span as `Misc.VirtualSize` (`tools/pe_map.cpp:95`). A TLS directory or a callback-table terminator placed in that tail was rejected as unmapped or truncated, and the slot count stopped at the raw end. Reproduction against the source-built `intake_forward_caller.exe` (`.data`: `VirtualAddress` 0xc000, `Misc_VirtualSize` 0x2b9, `SizeOfRawData` 0x200) with the TLS directory at RVA 0xc200: ```text Section: .data VA= 0xc000 VSize= 0x2b9 RawSize= 0x200 pe.get_data(tail_rva, 40) len: 0 ValueError: Unmapped or unsuitable RVA 0xc200 ``` ## Change - `section_for()` and the TLS callback slot bound use `Misc_VirtualSize` (falling back to `SizeOfRawData` when it is zero, clamped to `SizeOfImage`), matching the loader. - `read_rva()` reads the file-backed prefix and zero-fills the rest of a request from the uninitialized virtual tail; a short file-backed prefix still raises `Truncated data at RVA ...`. One behavior, no unrelated changes. ## Test `tests/intake/check.py` gains `check_virtual_tail_tls()`. It extends the last section's `VirtualSize` past its raw data so the tail exists under either linker layout (Debug and Release lay the fixtures out differently), then checks: - a table terminated by the tail's implicit zero slot parses as one callback; - a TLS directory wholly inside the tail parses as an empty directory; - a directory crossing from raw data into the tail parses the same way; - negative control: a directory that leaves the section's virtual span is still rejected (`Unmapped or unsuitable RVA ...`); - negative control: the same table is still rejected as unterminated when `VirtualSize` stops claiming the tail. The new test fails on `main` (`Unterminated TLS callback table or inspection limit reached`) and passes with the fix, on both `dev` and `release`. ## Verification Environment: Windows 11, Python 3.13.12 (`out/pe-env`, pefile 2024.8.26), MSVC 19.50.35726, Windows SDK 10.0.26100.0, CMake 4.5.1 + Ninja. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R 'static_exe_intake|conditional_import_paths|bundled_export_forwarders' # 3/3 passed, 100%, exit 0 cmake --preset release cmake --build --preset release ctest --preset release --no-tests=error -R '^static_exe_intake$' # 1/1 passed, 100%, exit 0 out\pe-env\Scripts\python.exe -B tests/intake/paths_check.py # exit 0 ``` Before the fix the issue reproduction exited 1 with `ValueError: Unmapped or unsuitable RVA 0xc200`; after the fix it exits 0 and the intake report lists the parsed TLS callbacks. This is fixture evidence for the loader-bound behavior, not full-game startup evidence. Fixes #744
upstream-sync closed this pull request 2026-11-24 06:44:40 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!754
No description provided.