Scripts: check NumberOfRvaAndSizes before reading PE exports #1494

Open
github-bot wants to merge 1 commit from github-bot/gh-1494 into main AGit
Owner

@⁠microwave805 on GitHub · 2026-11-24 16:54 UTC · original
microwave805:scripts-pe-exports-ndirs → main · +29 −3 · 2 files · 1 commits · open

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.
**@⁠microwave805** on GitHub · 2026-11-24 16:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1494) `microwave805:scripts-pe-exports-ndirs` → `main` · +29 −3 · 2 files · 1 commits · open `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.
pe_exports.py read 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 as the export RVA and crashed with ValueError instead of printing (no exports).

Verify SizeOfOptionalHeader and NumberOfRvaAndSizes > 0 before unpacking the export directory entry. Synthetic PE32 and PE32+ fixtures with zero data directories failed before the fix and pass afterward.

Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:55:32 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 18:53 UTC · original

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!

**@⁠DavidM1911** on GitHub · 2026-11-24 18:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/1494#issuecomment-7141298079) 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!
Author
Owner

@⁠microwave805 on GitHub · 2026-11-24 19:01 UTC · original

@⁠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).)

**@⁠microwave805** on GitHub · 2026-11-24 19:01 UTC · [original](https://github.com/xcl-dev/xcl/pull/1494#issuecomment-7141495205) @⁠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).)*
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-26 03:27 UTC · original · edited 2026-11-26 03:33 UTC

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.

**@⁠RavenCurseBurg** on GitHub · 2026-11-26 03:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1494#issuecomment-7181736544) · edited 2026-11-26 03:33 UTC 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1494/head:github-bot/gh-1494'
git switch 'github-bot/gh-1494'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1494'
git switch 'github-bot/gh-1494'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1494'
git switch 'github-bot/gh-1494'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1494'
git switch 'main'
git merge --squash 'github-bot/gh-1494'
git switch 'main'
git merge --ff-only 'github-bot/gh-1494'
git switch 'main'
git merge 'github-bot/gh-1494'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.