pe: locate the TLS directory by VirtualAddress in intake_exe #171

Merged
Vonsek merged 1 commit from upstream-pr/172 into main 2026-11-21 18:09:54 +00:00
Vonsek commented 2026-11-21 17:55:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T17:55:54Z.


Change

Locate the PE32+ TLS directory by VirtualAddress alone in tools/intake_exe.py (inspect_executable), matching the Windows loader and pe_map.

Previously, inspect_executable rejected any image with DATA_DIRECTORY[9].VirtualAddress != 0 and Size < 40, as well as any image with VirtualAddress == 0 and Size != 0, with Incomplete TLS directory. As verified against Windows in cpu_native_tls, the loader ignores the TLS directory Size field: a nonzero VirtualAddress with Size 0 or 39 still runs TLS callbacks, and VirtualAddress == 0 with nonzero Size has no TLS directory.

inspect_executable now reads the 40-byte IMAGE_TLS_DIRECTORY64 whenever VirtualAddress != 0, with full section and SizeOfImage bounds checking via read_rva(d.VirtualAddress, 40).

tests/intake/check.py adds four cases on patched copies of the source-built intake_candidate.exe:

  • Size = 0 and Size = 39 with nonzero VirtualAddress preserve pe.tls and pe.startup.locations;
  • VirtualAddress = 0 with Size = 40 reports pe.tls = None and only the entry point in pe.startup.locations;
  • out-of-bounds VirtualAddress = SizeOfImage - 16 with Size = 0 is rejected with an RVA bounds error.

Verification

Tested on Windows 11 x64, VS 2022 Build Tools 17.14 (MSVC 19.44.35230.0), Windows SDK 10.0.26100, Python 3.12.10 (pefile==2024.8.26), at commit 29fa4bf:

  • Before the change in tools/intake_exe.py, static_exe_intake fails on the Size = 0 case:
    ctest --preset dev --no-tests=error -R '^static_exe_intake$' -V
    AssertionError: ('error | ...\nIncomplete TLS directory\n', '')
    1/1 Test #89: static_exe_intake ................***Failed    1.94 sec
    
  • After the change:
    ctest --preset dev --no-tests=error -R '^(static_exe_intake|conditional_import_paths|bundled_export_forwarders)$' -V
    1/3 Test #88: conditional_import_paths .........   Passed    0.10 sec
    2/3 Test #89: static_exe_intake ................   Passed    3.24 sec
    3/3 Test #90: bundled_export_forwarders ........   Passed    0.24 sec
    100% tests passed, 0 tests failed out of 3
    

Evidence and follow-up

All new cases patch copies of the existing source-built intake_candidate.exe in a temporary directory without loading or executing the fixture.

The Windows loader behavior for Size 0/1/39, VirtualAddress == 0, and out-of-bounds TLS directories is already cross-checked live in tests/cpu/native_tls_check.py (cpu_native_tls).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532411855 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/172). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T17:55:54Z. --- ## Change Locate the PE32+ TLS directory by `VirtualAddress` alone in `tools/intake_exe.py` (`inspect_executable`), matching the Windows loader and `pe_map`. Previously, `inspect_executable` rejected any image with `DATA_DIRECTORY[9].VirtualAddress != 0` and `Size < 40`, as well as any image with `VirtualAddress == 0` and `Size != 0`, with `Incomplete TLS directory`. As verified against Windows in `cpu_native_tls`, the loader ignores the TLS directory `Size` field: a nonzero `VirtualAddress` with `Size` 0 or 39 still runs TLS callbacks, and `VirtualAddress == 0` with nonzero `Size` has no TLS directory. `inspect_executable` now reads the 40-byte `IMAGE_TLS_DIRECTORY64` whenever `VirtualAddress != 0`, with full section and `SizeOfImage` bounds checking via `read_rva(d.VirtualAddress, 40)`. `tests/intake/check.py` adds four cases on patched copies of the source-built `intake_candidate.exe`: - `Size = 0` and `Size = 39` with nonzero `VirtualAddress` preserve `pe.tls` and `pe.startup.locations`; - `VirtualAddress = 0` with `Size = 40` reports `pe.tls = None` and only the entry point in `pe.startup.locations`; - out-of-bounds `VirtualAddress = SizeOfImage - 16` with `Size = 0` is rejected with an RVA bounds error. ## Verification Tested on Windows 11 x64, VS 2022 Build Tools 17.14 (MSVC 19.44.35230.0), Windows SDK 10.0.26100, Python 3.12.10 (`pefile==2024.8.26`), at commit `29fa4bf`: - Before the change in `tools/intake_exe.py`, `static_exe_intake` fails on the `Size = 0` case: ```text ctest --preset dev --no-tests=error -R '^static_exe_intake$' -V AssertionError: ('error | ...\nIncomplete TLS directory\n', '') 1/1 Test #89: static_exe_intake ................***Failed 1.94 sec ``` - After the change: ```text ctest --preset dev --no-tests=error -R '^(static_exe_intake|conditional_import_paths|bundled_export_forwarders)$' -V 1/3 Test #88: conditional_import_paths ......... Passed 0.10 sec 2/3 Test #89: static_exe_intake ................ Passed 3.24 sec 3/3 Test #90: bundled_export_forwarders ........ Passed 0.24 sec 100% tests passed, 0 tests failed out of 3 ``` ## Evidence and follow-up All new cases patch copies of the existing source-built `intake_candidate.exe` in a temporary directory without loading or executing the fixture. The Windows loader behavior for `Size` 0/1/39, `VirtualAddress == 0`, and out-of-bounds TLS directories is already cross-checked live in `tests/cpu/native_tls_check.py` (`cpu_native_tls`). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:41:39 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:47:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T17:58:20Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T18:00:26.073021Z 29fa4bf Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066904532 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/172#issuecomment-7066904532). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T17:58:20Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"29fa4bf9f4be10430a3f1832da07d8a4d5291095","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T18:00:26.073021Z">2026-11-21T18:00:26.073021Z</relative-time> | `29fa4bf` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
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!171
No description provided.