cpu: guard short data-directory tables and executable flag in cpu_exe_aot #240

Manually merged
github merged 1 commit from gh-pr/240/head into gh-pr/240/base 2026-11-26 21:36:47 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 18:59 UTC · original
Vonsek:ag/cpu-exe-header-guards → main · +51 −3 · 3 files · 1 commits · merged 2026-11-21 19:12 UTC

Change

Fix two PE32+ header checks in tools/cpu_exe_aot.py (translate):

  • check len(pe.OPTIONAL_HEADER.DATA_DIRECTORY) > 9 before reading the TLS directory slot, so valid PE32+ executables with NumberOfRvaAndSizes <= 9 do not crash with IndexError;
  • require IMAGE_FILE_EXECUTABLE_IMAGE (FILE_HEADER.Characteristics & 2), matching tools/intake_exe.py.

Adds check_header_guards to tests/cpu/exe_entry_check.py (passing cpu_exe_io and cpu_import_provider from CMakeLists.txt), testing patched copies of the source-built cpu_exe_original.exe:

  • a 4-directory (NumberOfRvaAndSizes = 4) positive control that must translate identically to the unpatched executable;
  • three rejection controls: a nonzero TLS directory VirtualAddress, IMAGE_FILE_DLL set, and IMAGE_FILE_EXECUTABLE_IMAGE cleared.

Verification

Tested on Windows 11 x64, VS 2022 Build Tools 17.14 (MSVC 19.44.35230.0, ML64 14.44.35230.0), Windows SDK 10.0.26100, Python 3.12.10 (pefile==2024.8.26, iced-x86==1.21.0), at commit 69400db:

  • Before the fix in tools/cpu_exe_aot.py, cpu_aot_exe_entry fails on the 4-directory case:
    ctest --preset dev --no-tests=error -R '^cpu_aot_exe_entry$' -V
    File "tools/cpu_exe_aot.py", line 25, in translate
      if pe.OPTIONAL_HEADER.DATA_DIRECTORY[9].VirtualAddress:
    IndexError: list index out of range
    1/1 Test #81: cpu_aot_exe_entry ................***Failed    0.38 sec
    
  • After the fix:
    cmake --build --preset dev --target cpu_exe_original_lifted cpu_exe_inverted_lifted
    ctest --preset dev --no-tests=error -R '^cpu_aot_exe_entry$' -V
    selector=0 import=(0x100000303, 0xfffffffd) output=1103000000000000 exit=0x60d (inversion detected)
    selector=1 import=(0x30, 0x6) output=3500000000000000 exit=0x57 (inversion detected)
    4-directory EXE translation and 3 PE header rejection controls passed
    1/1 Test #81: cpu_aot_exe_entry ................   Passed    1.97 sec
    

Evidence and follow-up

All new checks operate on patched temporary copies of the existing source-built cpu_exe_original.exe without loading or executing the mutated copies.

The entry profile's supported instructions, frame bounds, and TLS exclusion remain unchanged.

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.
**@⁠Vonsek** on GitHub · 2026-11-21 18:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/240) `Vonsek:ag/cpu-exe-header-guards` → `main` · +51 −3 · 3 files · 1 commits · merged 2026-11-21 19:12 UTC ## Change Fix two PE32+ header checks in `tools/cpu_exe_aot.py` (`translate`): - check `len(pe.OPTIONAL_HEADER.DATA_DIRECTORY) > 9` before reading the TLS directory slot, so valid PE32+ executables with `NumberOfRvaAndSizes <= 9` do not crash with `IndexError`; - require `IMAGE_FILE_EXECUTABLE_IMAGE` (`FILE_HEADER.Characteristics & 2`), matching `tools/intake_exe.py`. Adds `check_header_guards` to `tests/cpu/exe_entry_check.py` (passing `cpu_exe_io` and `cpu_import_provider` from `CMakeLists.txt`), testing patched copies of the source-built `cpu_exe_original.exe`: - a 4-directory (`NumberOfRvaAndSizes = 4`) positive control that must translate identically to the unpatched executable; - three rejection controls: a nonzero TLS directory `VirtualAddress`, `IMAGE_FILE_DLL` set, and `IMAGE_FILE_EXECUTABLE_IMAGE` cleared. ## Verification Tested on Windows 11 x64, VS 2022 Build Tools 17.14 (MSVC 19.44.35230.0, ML64 14.44.35230.0), Windows SDK 10.0.26100, Python 3.12.10 (`pefile==2024.8.26`, `iced-x86==1.21.0`), at commit `69400db`: - Before the fix in `tools/cpu_exe_aot.py`, `cpu_aot_exe_entry` fails on the 4-directory case: ```text ctest --preset dev --no-tests=error -R '^cpu_aot_exe_entry$' -V File "tools/cpu_exe_aot.py", line 25, in translate if pe.OPTIONAL_HEADER.DATA_DIRECTORY[9].VirtualAddress: IndexError: list index out of range 1/1 Test #81: cpu_aot_exe_entry ................***Failed 0.38 sec ``` - After the fix: ```text cmake --build --preset dev --target cpu_exe_original_lifted cpu_exe_inverted_lifted ctest --preset dev --no-tests=error -R '^cpu_aot_exe_entry$' -V selector=0 import=(0x100000303, 0xfffffffd) output=1103000000000000 exit=0x60d (inversion detected) selector=1 import=(0x30, 0x6) output=3500000000000000 exit=0x57 (inversion detected) 4-directory EXE translation and 3 PE header rejection controls passed 1/1 Test #81: cpu_aot_exe_entry ................ Passed 1.97 sec ``` ## Evidence and follow-up All new checks operate on patched temporary copies of the existing source-built `cpu_exe_original.exe` without loading or executing the mutated copies. The entry profile's supported instructions, frame bounds, and TLS exclusion remain unchanged. ## 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.
cpu_exe_aot.translate previously indexed OPTIONAL_HEADER.DATA_DIRECTORY[9] unconditionally (raising IndexError on valid PE32+ executables with NumberOfRvaAndSizes <= 9) and did not check IMAGE_FILE_EXECUTABLE_IMAGE (Characteristics & 2). Check len(DATA_DIRECTORY) > 9 before reading the TLS slot and require IMAGE_FILE_EXECUTABLE_IMAGE, matching intake_exe.py. Add a 4-directory positive control and three PE header rejection controls (TLS directory, IMAGE_FILE_DLL, cleared IMAGE_FILE_EXECUTABLE_IMAGE) to tests/cpu/exe_entry_check.py.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:36:45 +00:00
github manually merged commit 69400dbade into gh-pr/240/base 2026-11-26 21:36:47 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 19:02 UTC · original · edited 2026-11-21 19:04 UTC

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-21T19:04:09.717686Z 69400db 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 19:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/240#issuecomment-7067712741) · edited 2026-11-21 19:04 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"69400dbade5197f931d2d34018d6158f51151483","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-21T19:04:09.717686Z">2026-11-21T19:04:09.717686Z</relative-time> | `69400db` | 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>
This discussion has been locked. Commenting is limited to contributors.
No description provided.