Scripts: read PE exports stored in image headers #1685

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

@⁠jeroenhaentjens on GitHub · 2026-11-24 19:15 UTC · original
jeroenhaentjens:scripts/pe-header-exports → main · +43 −0 · 3 files · 1 commits · open

scripts/re/pe_exports.py raises ValueError: 0x200 for exports stored in PE image headers. Resolve header RVAs directly, bounded by SizeOfHeaders and file length, before searching sections.

What is in it

  • Three-line fix, synthetic PE32/PE32+ regression test, and README note. No Rust/runtime changes.

Tested

  • PR 30852cf11b086bef9daaf8de3450122d2a0a3068; base c160d86ef2efe3a07e4dfb473e4fa72eafb413c0.
  • Windows 11 Pro 26200, i7-9750H, 32 GB RAM, NVIDIA Quadro RTX 3000 (driver 32.0.15.9706), Rust/Cargo 1.100.0 MSVC, VS Build Tools 17.14.45, Windows SDK 10.0.26100.0, DXC 1.9.2609.5, Python 3.10.0.
  • Unoptimized debug builds; CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0 to limit disk usage. XCL_ADAPTER=nvidia; XCL_DXC_DIR points to DXC's x64 binaries.
  • cargo build --workspace --locked: passed on PR and base.
  • cargo test --workspace --locked --no-fail-fast -- --test-threads=4: final PR run 858 passed, 0 failed, 42 ignored; base run identical. Built-in test-title e2e tests passed.
  • Initial PR run: 857 passed, 1 failed, 42 ignored. coherent_buffer_sanitizes_console_flags_and_state failed its VirtualFree assertion at real.rs:5825. The exact test passed alone (cargo test -p xcl --lib coherent_buffer_sanitizes_console_flags_and_state -- --test-threads=1 --nocapture); a full rerun passed with no source changes. Cause remains unconfirmed; this intermittent result is disclosed for maintainer review.
  • Three GPU skips are included in Cargo's passed count: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no native wave64); heap_window_out_of_memory_falls_back_to_the_switch_form (opt-in disabled).
  • Separately, with XCL_HEAP_WINDOWS=1: cargo test -p xcl --test gpu_compute_e2e heap_window_out_of_memory_falls_back_to_the_switch_form -- --exact --test-threads=1 --nocapture: 1 passed, 0 failed, no GPU skips, real NVIDIA backend confirmed.
  • python -m unittest discover -s scripts -p 'test_*.py' -v: 17 passed, 0 failed, 0 skipped. New regression fails on unpatched main for both PE32/PE32+.
  • git diff --check: passed; working tree clean.

Regression run

  • Retail smoke blocks not required: script/tests/README only.

Not tested

  • Native wave64/AMD hardware, the 42 explicitly ignored tests, and real game/console SDK data. No XCL_SAMPLE_* inputs supplied: tests that return early without sample data are not retail coverage, even when Cargo reports them as passed.

AI use

  • Codex (GPT-6) investigated, wrote the patch/tests, installed build prerequisites, ran validation and prepared this description.
**@⁠jeroenhaentjens** on GitHub · 2026-11-24 19:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1685) `jeroenhaentjens:scripts/pe-header-exports` → `main` · +43 −0 · 3 files · 1 commits · open `scripts/re/pe_exports.py` raises `ValueError: 0x200` for exports stored in PE image headers. Resolve header RVAs directly, bounded by `SizeOfHeaders` and file length, before searching sections. **What is in it** - Three-line fix, synthetic PE32/PE32+ regression test, and README note. No Rust/runtime changes. **Tested** - PR `30852cf11b086bef9daaf8de3450122d2a0a3068`; base `c160d86ef2efe3a07e4dfb473e4fa72eafb413c0`. - Windows 11 Pro 26200, i7-9750H, 32 GB RAM, NVIDIA Quadro RTX 3000 (driver 32.0.15.9706), Rust/Cargo 1.100.0 MSVC, VS Build Tools 17.14.45, Windows SDK 10.0.26100.0, DXC 1.9.2609.5, Python 3.10.0. - Unoptimized debug builds; `CARGO_INCREMENTAL=0`, `CARGO_PROFILE_DEV_DEBUG=0`, `CARGO_PROFILE_TEST_DEBUG=0` to limit disk usage. `XCL_ADAPTER=nvidia`; `XCL_DXC_DIR` points to DXC's x64 binaries. - `cargo build --workspace --locked`: passed on PR and base. - `cargo test --workspace --locked --no-fail-fast -- --test-threads=4`: final PR run **858 passed, 0 failed, 42 ignored**; base run identical. Built-in test-title e2e tests passed. - Initial PR run: 857 passed, 1 failed, 42 ignored. `coherent_buffer_sanitizes_console_flags_and_state` failed its `VirtualFree` assertion at `real.rs:5825`. The exact test passed alone (`cargo test -p xcl --lib coherent_buffer_sanitizes_console_flags_and_state -- --test-threads=1 --nocapture`); a full rerun passed with no source changes. Cause remains unconfirmed; this intermittent result is disclosed for maintainer review. - Three GPU skips are included in Cargo's passed count: `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` (no native wave64); `heap_window_out_of_memory_falls_back_to_the_switch_form` (opt-in disabled). - Separately, with `XCL_HEAP_WINDOWS=1`: `cargo test -p xcl --test gpu_compute_e2e heap_window_out_of_memory_falls_back_to_the_switch_form -- --exact --test-threads=1 --nocapture`: **1 passed, 0 failed, no GPU skips**, real NVIDIA backend confirmed. - `python -m unittest discover -s scripts -p 'test_*.py' -v`: 17 passed, 0 failed, 0 skipped. New regression fails on unpatched main for both PE32/PE32+. - `git diff --check`: passed; working tree clean. **Regression run** - Retail smoke blocks not required: script/tests/README only. **Not tested** - Native wave64/AMD hardware, the 42 explicitly ignored tests, and real game/console SDK data. No `XCL_SAMPLE_*` inputs supplied: tests that return early without sample data are not retail coverage, even when Cargo reports them as passed. **AI use** - Codex (GPT-6) investigated, wrote the patch/tests, installed build prerequisites, ran validation and prepared this description.
Resolve header RVAs directly before searching section ranges. Add synthetic
PE32 and PE32+ regressions that fail on main with ValueError: 0x200.

Assisted-by: Codex (GPT-6)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:01:33 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 21:47 UTC · original

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

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

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 21:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1685#issuecomment-7145394352) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-26 01:38 UTC · original · edited 2026-11-26 01:52 UTC

Tested 30852cf11b086bef9daaf8de3450122d2a0a3068 against the same header RVA change ported onto #1814 (parent 0180bf493cb1).

I ran python -B scripts/re/pe_exports.py <eight fixtures> %WINDIR%\System32\version.dll %WINDIR%\SysWOW64\version.dll with all ten paths in one invocation on each revision. The two readers printed identical output for all ten files.

  • For both PE32 and PE32+, I placed the export directory and the names in the headers, in a section, and in each of the two mixed placements. Each listing showed ordinal 7, FixtureValue, RVA 0x1180.
  • Both installed Windows DLLs listed 17 functions and 17 names, including GetFileVersionInfoW and VerQueryValueW. I checked the optional header magic independently for each DLL.
  • On #1814 alone, this PR’s existing header-directory test failed for both PE formats. On the integration, python -B -m unittest discover -s scripts -p "test_pe_exports.py" passed all 9 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 checks. No DLL was loaded; the runtime, GPU and game suite were not exercised.

**@⁠RavenCurseBurg** on GitHub · 2026-11-26 01:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/1685#issuecomment-7179981009) · edited 2026-11-26 01:52 UTC Tested `30852cf11b086bef9daaf8de3450122d2a0a3068` against [the same header RVA change ported onto #1814](https://github.com/RavenCurseBurg/xcl/commit/d02109c3cfda71517b9d332be92ca868e241770c) (parent `0180bf493cb1`). I ran `python -B scripts/re/pe_exports.py <eight fixtures> %WINDIR%\System32\version.dll %WINDIR%\SysWOW64\version.dll` with all ten paths in one invocation on each revision. The two readers printed identical output for all ten files. - For both PE32 and PE32+, I placed the export directory and the names in the headers, in a section, and in each of the two mixed placements. Each listing showed ordinal 7, `FixtureValue`, RVA `0x1180`. - Both installed Windows DLLs listed 17 functions and 17 names, including `GetFileVersionInfoW` and `VerQueryValueW`. I checked the optional header magic independently for each DLL. - On #1814 alone, this PR’s existing header-directory test failed for both PE formats. On the integration, `python -B -m unittest discover -s scripts -p "test_pe_exports.py"` passed all 9 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 checks. No DLL was loaded; the runtime, GPU and game suite were not exercised.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 05:36 UTC · original · reviewed

Could header string reads stop at SizeOfHeaders as well as checking the starting RVA? off() accepts a name RVA inside the headers, but cstr() then scans the entire file for NUL. In the existing PE32 and PE32+ synthetic fixtures, moving HeaderExport to file offset 0x3FC with SizeOfHeaders=0x400 still prints HeaderExport: only Head is in the mapped headers and the suffix comes from unrelated .text bytes on disk. Carrying a mapped-region bound into cstr() would reject that name; fixed-width table reads need the same boundary check. Reproduced on exact head 30852cf11b086bef9daaf8de3450122d2a0a3068; no DLL was loaded. AI-assisted review with Codex.

**@⁠luckyteagirl** on GitHub · 2026-11-26 05:36 UTC · [original](https://github.com/xcl-dev/xcl/pull/1685#pullrequestreview-6069052197) · **reviewed** Could header string reads stop at `SizeOfHeaders` as well as checking the starting RVA? `off()` accepts a name RVA inside the headers, but `cstr()` then scans the entire file for NUL. In the existing PE32 and PE32+ synthetic fixtures, moving `HeaderExport` to file offset `0x3FC` with `SizeOfHeaders=0x400` still prints `HeaderExport`: only `Head` is in the mapped headers and the suffix comes from unrelated `.text` bytes on disk. Carrying a mapped-region bound into `cstr()` would reject that name; fixed-width table reads need the same boundary check. Reproduced on exact head `30852cf11b086bef9daaf8de3450122d2a0a3068`; no DLL was loaded. AI-assisted review with Codex.
This pull request has changes conflicting with the target branch.
  • README.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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