Scripts: check NumberOfRvaAndSizes before reading PE exports #1484

Open
microwave805 wants to merge 1 commit from upstream-pr/1494 into main
microwave805 commented 2026-11-24 16:54:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-24T16:54:22Z.


scripts/re/pe_exports.py unpacked the export data directory unconditionally at offset +96/+112 of the optional header without checking SizeOfOptionalHeader or NumberOfRvaAndSizes. On a PE with zero data directories, it read the first section header name (such as .text) as the export table RVA and crashed with ValueError instead of printing (no exports).

What is in it

  • scripts/re/pe_exports.py: read SizeOfOptionalHeader and NumberOfRvaAndSizes and treat the export directory as (0, 0) when NumberOfRvaAndSizes == 0 or the optional header does not contain the first data directory entry.
  • scripts/test_pe_exports.py: add synthetic PE32 and PE32+ fixtures with NumberOfRvaAndSizes = 0 immediately followed by a .text section header and verify (no exports) is printed.

Tested

  • NVIDIA GeForce RTX 3070 (driver 32.0.16.1742), AMD Ryzen 5 5600X, Windows 11 Pro (build 22631), DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc, debug), Python 3.11.3
  • Before the fix: python -I -m unittest discover -s scripts -p "test_pe_exports.py" -v: 1 passed, 2 subtest errors (both PE32 and PE32+ exited with status 1)
  • On PR head 130b1a8:
    • python -I -m unittest discover -s scripts -p "test_*.py" -v: 17 passed, 0 failed
    • .\scripts\test.ps1 (cargo build --workspace && cargo test --workspace -- --test-threads=4): 770 passed, 0 failed, 41 ignored
    • SKIPPED GPU tests: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Regression run

  • Not needed: changes only scripts/re/pe_exports.py and scripts/test_pe_exports.py (no runtime or build-input files).

Not tested

  • Real console DLLs (no console binaries)
  • AMD / wave64 GPUs and retail titles

AI use

  • Antigravity (Gemini 4 Neon): identified the missing NumberOfRvaAndSizes check in scripts/re/pe_exports.py, wrote the fix, unit test, and PR description, and ran the verification commands above.
<!-- greyfinch-sync:ivall/xcl:issue:5476581943 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1494). Originally posted by [microwave805](https://github.com/microwave805) on 2026-11-24T16:54:22Z. --- `scripts/re/pe_exports.py` unpacked the export data directory unconditionally at offset `+96`/`+112` of the optional header without checking `SizeOfOptionalHeader` or `NumberOfRvaAndSizes`. On a PE with zero data directories, it read the first section header name (such as `.text`) as the export table RVA and crashed with `ValueError` instead of printing `(no exports)`. **What is in it** - `scripts/re/pe_exports.py`: read `SizeOfOptionalHeader` and `NumberOfRvaAndSizes` and treat the export directory as `(0, 0)` when `NumberOfRvaAndSizes == 0` or the optional header does not contain the first data directory entry. - `scripts/test_pe_exports.py`: add synthetic PE32 and PE32+ fixtures with `NumberOfRvaAndSizes = 0` immediately followed by a `.text` section header and verify `(no exports)` is printed. **Tested** - NVIDIA GeForce RTX 3070 (driver 32.0.16.1742), AMD Ryzen 5 5600X, Windows 11 Pro (build 22631), DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`, debug), Python 3.11.3 - Before the fix: `python -I -m unittest discover -s scripts -p "test_pe_exports.py" -v`: 1 passed, 2 subtest errors (both PE32 and PE32+ exited with status 1) - On PR head `130b1a8`: - `python -I -m unittest discover -s scripts -p "test_*.py" -v`: 17 passed, 0 failed - `.\scripts\test.ps1` (`cargo build --workspace && cargo test --workspace -- --test-threads=4`): 770 passed, 0 failed, 41 ignored - SKIPPED GPU tests: `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware` (no wave64) **Regression run** - Not needed: changes only `scripts/re/pe_exports.py` and `scripts/test_pe_exports.py` (no runtime or build-input files). **Not tested** - Real console DLLs (no console binaries) - AMD / wave64 GPUs and retail titles **AI use** - Antigravity (Gemini 4 Neon): identified the missing `NumberOfRvaAndSizes` check in `scripts/re/pe_exports.py`, wrote the fix, unit test, and PR description, and ran the verification commands above.
gut0to commented 2026-11-24 18:53:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:53:05Z.

Review: COMMENTED


The Python tests cover the new parser checks, but the workspace test command in this description was run on the base, not this PR head. CONTRIBUTING.md requires the full workspace suite on the PR head (on Windows, with GPU and skipped-test details). Please add that result before merge. AI-assisted review; I checked the commit and Tested section.

<!-- greyfinch-sync:ivall/xcl:review:6045385869 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1494#pullrequestreview-6045385869). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-24T18:53:05Z. **Review:** COMMENTED --- The Python tests cover the new parser checks, but the workspace test command in this description was run on the base, not this PR head. CONTRIBUTING.md requires the full workspace suite on the PR head (on Windows, with GPU and skipped-test details). Please add that result before merge. AI-assisted review; I checked the commit and Tested section.
DavidM1911 commented 2026-11-24 19:07:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:53:33Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7141298079 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1494#issuecomment-7141298079). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T18:53:33Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
microwave805 commented 2026-11-24 19:07:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-24T19:01:56Z.


@gut0to Thanks for checking — I ran .\scripts\test.ps1 directly on PR head 130b1a8 (RTX 3070, Windows 11): 770 passed, 0 failed, 41 ignored (2 SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware — no wave64), and updated Tested in the description.

(Comment drafted with Antigravity (Gemini 4 Neon).)

<!-- greyfinch-sync:ivall/xcl:comment:7141495205 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1494#issuecomment-7141495205). Originally posted by [microwave805](https://github.com/microwave805) on 2026-11-24T19:01:56Z. --- @gut0to Thanks for checking — I ran `.\scripts\test.ps1` directly on PR head `130b1a8` (RTX 3070, Windows 11): 770 passed, 0 failed, 41 ignored (2 `SKIPPED`: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` — `no wave64`), and updated **Tested** in the description. *(Comment drafted with Antigravity (Gemini 4 Neon).)*
RavenCurseBurg commented 2026-11-26 04:07:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by RavenCurseBurg on 2026-11-26T03:27:31Z.


Tested 130b1a813d020731105a6deabfd20ac8fbececbd on Windows with valid PE32 and PE32+ files whose optional headers ended immediately after the zero directory count, and with zero-directory files retaining the padding. I interleaved export-free files with files that had exports, then added the installed 32-bit and 64-bit Windows version.dll. Running python -B scripts/re/pe_exports.py <files...> on this PR printed all eight expected listings in argument order and exited 0. Its two targeted unittest methods also passed.

I then repeated the batch with two extra files whose exports reside in headers. The previous #1685/#1814 integration produced eight listings and returned 1 for the two compact files. This change ported to that reader produced all ten listings and exited 0. I checked the no-exports lines, ordinal 7 and RVA 0x1180 for the synthetic named export, and GetFileVersionInfoW and VerQueryValueW in both system DLLs.

On the integrated candidate, python -B -m unittest discover -s scripts -p "test_*.py" passed all 25 tests, with no failures or skips. Windows build 26100, i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) ported the change and ran these read-only tests. The DLLs were read from disk. The runtime, GPU and games were outside this run.

<!-- greyfinch-sync:ivall/xcl:comment:7181736544 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1494#issuecomment-7181736544). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T03:27:31Z. --- Tested `130b1a813d020731105a6deabfd20ac8fbececbd` on Windows with valid PE32 and PE32+ files whose optional headers ended immediately after the zero directory count, and with zero-directory files retaining the padding. I interleaved export-free files with files that had exports, then added the installed 32-bit and 64-bit Windows `version.dll`. Running `python -B scripts/re/pe_exports.py <files...>` on this PR printed all eight expected listings in argument order and exited 0. Its two targeted unittest methods also passed. I then repeated the batch with two extra files whose exports reside in headers. The previous #1685/#1814 integration produced eight listings and returned 1 for the two compact files. [This change ported to that reader](https://github.com/RavenCurseBurg/xcl/commit/bccbfa2f65c2f399bddc6664016820cdf375a0a1) produced all ten listings and exited 0. I checked the no-exports lines, ordinal 7 and RVA `0x1180` for the synthetic named export, and `GetFileVersionInfoW` and `VerQueryValueW` in both system DLLs. On the integrated candidate, `python -B -m unittest discover -s scripts -p "test_*.py"` passed all 25 tests, with no failures or skips. Windows build 26100, i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) ported the change and ran these read-only tests. The DLLs were read from disk. The runtime, GPU and games were outside this run.
github-actions[bot] commented 2026-11-30 08:42:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:42:14Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7273237974 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1494#issuecomment-7273237974). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:42:14Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:55:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:55:43Z.


Triage (#1607) – head 130b1a8

#1685 (export directory inside the headers), #1814 (CLI/bounds hardening) and #2662 (file-backed RVA mapping) change scripts/re/pe_exports.py too; the shared lines are test-fixture boilerplate. None of them reads NumberOfRvaAndSizes, so with zero data directories they still take the section table as the export directory.
No problems found in the diff; the new test fails on main for both PE32 and PE32+.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302287498 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1494#issuecomment-7302287498). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:55:43Z. --- **Triage (#1607)** – head 130b1a8 #1685 (export directory inside the headers), #1814 (CLI/bounds hardening) and #2662 (file-backed RVA mapping) change scripts/re/pe_exports.py too; the shared lines are test-fixture boilerplate. None of them reads NumberOfRvaAndSizes, so with zero data directories they still take the section table as the export directory. No problems found in the diff; the new test fails on main for both PE32 and PE32+. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1494:upstream-pr/1494'
git switch 'upstream-pr/1494'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1494'
git switch 'upstream-pr/1494'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1494'
git switch 'upstream-pr/1494'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1494'
git switch 'main'
git merge --squash 'upstream-pr/1494'
git switch 'main'
git merge --ff-only 'upstream-pr/1494'
git switch 'main'
git merge 'upstream-pr/1494'
git push origin 'main'
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
xcl-dev/xcl!1484
No description provided.