Scripts: read PE exports stored in image headers #1675

Open
jeroenhaentjens wants to merge 1 commit from upstream-pr/1685 into main
jeroenhaentjens commented 2026-11-24 19:15:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-11-24T19:15:58Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5478699746 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1685). Originally posted by [jeroenhaentjens](https://github.com/jeroenhaentjens) on 2026-11-24T19:15:58Z. --- `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.
DavidM1911 commented 2026-11-24 22:06:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T21:47:35Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7145394352 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1685#issuecomment-7145394352). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T21:47:35Z. --- 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!
RavenCurseBurg commented 2026-11-26 02:08:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by RavenCurseBurg on 2026-11-26T01:38:45Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7179981009 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1685#issuecomment-7179981009). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T01:38:45Z. --- 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.
luckyteagirl commented 2026-11-26 05:36:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T05:36:48Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ivall/xcl:review:6069052197 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1685#pullrequestreview-6069052197). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T05:36:48Z. **Review:** COMMENTED --- 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.
github-actions[bot] commented 2026-12-01 02:32:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:32:45Z.


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:7298731708 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1685#issuecomment-7298731708). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:32:45Z. --- 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 06:29:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:29:19Z.


Triage (#1607) – head 30852cf

No open PR makes the same change. #2662 (map export RVAs only into file-backed section bytes), #1494 (check NumberOfRvaAndSizes) and #1814 (CLI hardening) change scripts/re/pe_exports.py differently; the shared lines are the synthetic-PE test setup. None of them reads RVAs below SizeOfHeaders.
#2662's raw_span would reject header RVAs, so whichever lands second has to keep the header path in off(). The SizeOfHeaders offset (optional header + 60) is right for 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:7302931086 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1685#issuecomment-7302931086). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:29:19Z. --- **Triage (#1607)** – head 30852cf No open PR makes the same change. #2662 (map export RVAs only into file-backed section bytes), #1494 (check NumberOfRvaAndSizes) and #1814 (CLI hardening) change `scripts/re/pe_exports.py` differently; the shared lines are the synthetic-PE test setup. None of them reads RVAs below SizeOfHeaders. #2662's `raw_span` would reject header RVAs, so whichever lands second has to keep the header path in `off()`. The `SizeOfHeaders` offset (optional header + 60) is right for 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/1685:upstream-pr/1685'
git switch 'upstream-pr/1685'

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/1685'
git switch 'upstream-pr/1685'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1685'
git switch 'upstream-pr/1685'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1685'
git switch 'main'
git merge --squash 'upstream-pr/1685'
git switch 'main'
git merge --ff-only 'upstream-pr/1685'
git switch 'main'
git merge 'upstream-pr/1685'
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!1675
No description provided.