cpu: AOT tools refuse malformed PE input with a message #1626

Merged
tedin7 merged 2 commits from upstream-pr/1633 into main 2026-11-24 16:04:25 +00:00
tedin7 commented 2026-11-24 15:28:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:28:43Z.


AI-assisted; commands listed were executed locally.

Two malformed-input crashes in the AOT command-line tools, one commit each.

  1. tools/cpu_ranges.py: function_ranges indexed DATA_DIRECTORY[3] without checking NumberOfRvaAndSizes. An image with fewer than four directories ended cpu_leaf_aot, cpu_call_aot and cpu_chained_aot with an IndexError traceback. It now raises a ValueError that the tools already print as one line.
  2. tools/cpu_exe_aot.py: the only translator whose command line did not catch OSError, ValueError and PEFormatError. A missing image or an unsupported image ended with a traceback. It now prints the reason and exits with status 1 like the other three.

New test tests/cpu/malformed_pe_check.py builds a small synthetic DLL (tests/cpu/synthetic_pe.py, no real binary) and checks a complete image translates (control), a short directory table is refused by the three tools, and the EXE tool refuses a missing image and a DLL image, each with exit status 1, a message and no traceback. Registered as cpu_aot_malformed_pe.

Commands executed locally (Linux, Python 3.14, pefile 2024.8.26, iced-x86):

  • python -B tests/cpu/malformed_pe_check.py: fails on origin/main (IndexError traceback, then the FileNotFoundError traceback), passes after each fix.
  • python -B tests/docs_links_check.py: passed (16 Markdown files, 348 links).
  • python -B tests/bidi_controls_check.py: passed (1267 tracked files).
  • git diff origin/main --check: clean.
  • Differential fuzz of the lifters against the original bytes run natively (not part of this PR): leaf 15000 cases, call 6000 valid plus 2300 accepted mutations, chained about 21000 runs, 0 mismatches; 36000 corrupted PE inputs gave no other uncaught exception.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit c81475419871b9a4daf344c31e2ef54bf086ce2c:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target cpu_leaf_original_lifted cpu_call_original_lifted cpu_chained_lifted -- -j 6): 3.04s (configure 1.73s)
    • Test (ctest --preset dev -R '^(cpu_aot_malformed_pe|cpu_leaf_aot_branches)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (1.41s: cpu_leaf_aot_branches 0.10s, cpu_aot_malformed_pe 1.34s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target cpu_leaf_original_lifted cpu_call_original_lifted cpu_chained_lifted -- -j 6): 0.42s (configure 1.78s)
    • Test (ctest --preset release -R '^(cpu_aot_malformed_pe|cpu_leaf_aot_branches)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (1.34s: cpu_leaf_aot_branches 0.10s, cpu_aot_malformed_pe 1.26s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6585327287 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1633). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:28:43Z. --- AI-assisted; commands listed were executed locally. Two malformed-input crashes in the AOT command-line tools, one commit each. 1. `tools/cpu_ranges.py`: `function_ranges` indexed `DATA_DIRECTORY[3]` without checking NumberOfRvaAndSizes. An image with fewer than four directories ended `cpu_leaf_aot`, `cpu_call_aot` and `cpu_chained_aot` with an IndexError traceback. It now raises a ValueError that the tools already print as one line. 2. `tools/cpu_exe_aot.py`: the only translator whose command line did not catch OSError, ValueError and PEFormatError. A missing image or an unsupported image ended with a traceback. It now prints the reason and exits with status 1 like the other three. New test `tests/cpu/malformed_pe_check.py` builds a small synthetic DLL (`tests/cpu/synthetic_pe.py`, no real binary) and checks a complete image translates (control), a short directory table is refused by the three tools, and the EXE tool refuses a missing image and a DLL image, each with exit status 1, a message and no traceback. Registered as `cpu_aot_malformed_pe`. Commands executed locally (Linux, Python 3.14, pefile 2024.8.26, iced-x86): - `python -B tests/cpu/malformed_pe_check.py`: fails on origin/main (IndexError traceback, then the FileNotFoundError traceback), passes after each fix. - `python -B tests/docs_links_check.py`: passed (16 Markdown files, 348 links). - `python -B tests/bidi_controls_check.py`: passed (1267 tracked files). - `git diff origin/main --check`: clean. - Differential fuzz of the lifters against the original bytes run natively (not part of this PR): leaf 15000 cases, call 6000 valid plus 2300 accepted mutations, chained about 21000 runs, 0 mismatches; 36000 corrupted PE inputs gave no other uncaught exception. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `c81475419871b9a4daf344c31e2ef54bf086ce2c`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target cpu_leaf_original_lifted cpu_call_original_lifted cpu_chained_lifted -- -j 6`): `3.04s` (configure `1.73s`) - Test (`ctest --preset dev -R '^(cpu_aot_malformed_pe|cpu_leaf_aot_branches)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`1.41s`: `cpu_leaf_aot_branches` `0.10s`, `cpu_aot_malformed_pe` `1.34s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target cpu_leaf_original_lifted cpu_call_original_lifted cpu_chained_lifted -- -j 6`): `0.42s` (configure `1.78s`) - Test (`ctest --preset release -R '^(cpu_aot_malformed_pe|cpu_leaf_aot_branches)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`1.34s`: `cpu_leaf_aot_branches` `0.10s`, `cpu_aot_malformed_pe` `1.26s`)
chatgpt-codex-connector[bot commented 2026-11-24 16:03:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T15:40:41Z.


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-24T15:43:28.737032Z c814754 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:7136427789 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1633#issuecomment-7136427789). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T15:40:41Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"c81475419871b9a4daf344c31e2ef54bf086ce2c","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-24T15:43:28.737032Z">2026-11-24T15:43:28.737032Z</relative-time> | `c814754` | 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>
upstream-sync closed this pull request 2026-11-24 17:01:44 +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!1626
No description provided.