Skip to content

PE loader: an import name at the top of the address space is an error - #1216

Open
Longno242 wants to merge 1 commit into
xcl-dev:mainfrom
Longno242:pe-import-name-overflow
Open

Longno242 wants to merge 1 commit into
xcl-dev:mainfrom
Longno242:pe-import-name-overflow

Conversation

@Longno242

@Longno242 Longno242 commented Nov 24, 2026 •

Copy link
Copy Markdown

A named import thunk stores the hint/name RVA. Adding 2 with wrapping turned 0xFFFFFFFE into RVA 0, so the parser accepted the DOS header (MZ) as the import name instead of rejecting the image.

What is in it

  • crates/xcl/src/pe.rs: checked_add(2) for the import name RVA; unit test with the hint at 0xFFFFFFFE inside a high section

Tested

  • Hardware/OS (full suite by @jennydeth): RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2609.5, debug build. Head b0a128c
  • Commit tested: b0a128c7503de9c7f2283e6e315a9ead9045f7a1 (clean tree)
  • cargo test --workspace -- --test-threads=4: 742 passed, 0 failed, 41 ignored. SKIPPED: 2 GPU tests for no wave64 (expected on this card)
  • SKIPPED: 2 GPU tests for no wave64 (expected on this card)
  • Retail smoke: see Regression run (@Toons29, RX 9070)
  • @DavidM1911 re-checked cargo test -p xcl --lib on RTX 3060 Ti after merging this head with current main locally: all passed, 0 failed, 27 ignored. The PR head itself is unchanged.

Regression run

  • Retail scripts/smoke.ps1 from @Toons29 (RX 9070, 60 s, same title/time; blocks as printed):
xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: b0a128c7503de9c7f2283e6e315a9ead9045f7a1
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1632 (PresentX 1632)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14816 MB

Not tested

  • Full cargo test --workspace

AI use

  • @jennydeth: Claude Code (Claude Opus 5.5) ran the full workspace suite and reported results in a PR comment
  • Cursor Auto (Composer): found the wrapping add on the import name RVA, implemented the checked add and test, opened this draft PR. Exact underlying model name not disclosed to the agent.

The hint RVA plus 2 used wrapping_add, so a name at 0xFFFFFFFE became
RVA 0 and the DOS header was read as the import name.

Assisted-by: Cursor Auto (Composer)
Co-authored-by: Cursor <cursoragent@cursor.com>
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib pe: 3 passed, 0 failed.

Note: the full d3d12x lib filter currently aborts with 0xc0000005 on unmodified main too (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of b0a128c7 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: b0a128c7503de9c7f2283e6e315a9ead9045f7a1
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1632 (PresentX 1632)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14816 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

@Longno242

Copy link
Copy Markdown
Author

Thanks @Toons29 — pasted both of your xcl-smoke v1 blocks under Regression run so the description check can see them.

@Longno242
Longno242 marked this pull request as ready for review November 25, 2026 12:44
@Longno242

Copy link
Copy Markdown
Author

CI is stuck on action_required (first-time contributor workflow approval). Smoke + PR description are green; please approve the pending CI workflow when you get a chance.

@jennydeth

Copy link
Copy Markdown

Full workspace run (listed under Not tested).

Setup: RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2609.5, debug build. Head b0a128c.

Result: cargo test --workspace -- --test-threads=4: 742 passed, 0 failed, 41 ignored. SKIPPED: 2 GPU tests for no wave64 (expected on this card).

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@Longno242

Copy link
Copy Markdown
Author

Thanks @jennydeth — copied your workspace counts into Tested (742 passed, 0 failed, 41 ignored. SKIPPED: 2 GPU tests for no wave64 (expected on this card)).

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

@Longno242

Copy link
Copy Markdown
Author

Thanks @DavidM1911 — noted the cargo test -p xcl --lib re-check (passed, 0 failed, 27 ignored) under Tested. Head commit is unchanged.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…r + ordinal overflow (port upstream xcl-dev#1216 + xcl-dev#1134 + xcl-dev#700)

Port all three complementary single-file pe.rs keepers verbatim
(pe.rs is shared, compiles on Linux — no twin needed):
- xcl-dev#1216: hn.checked_add(2) for the hint/name RVA (was wrapping_add)
  + import_name_at_the_top_of_the_address_space_is_error
- xcl-dev#1134: export_target propagates failed forwarder-string read as
  None (was leaking the RVA as an ordinary export address)
  + unterminated_forwarders_are_not_export_addresses (file+mapped)
- xcl-dev#700: from_pe ordinal loop uses checked_add + break past u32::MAX
  (was debug-panic / release-wrap to shadowing ordinal 0)
  + export_ordinals_past_u32_max_are_skipped

Failing-first: xcl-dev#1134 failed pre-fix (Some(Rva) vs None),
xcl-dev#700 failed pre-fix (attempt to add with overflow); xcl-dev#1216 passes
pre-fix too (0x7FFFFFFF hint mask already bounds hn, so +2 cannot
wrap on this path — ported verbatim for fidelity, zero behavior
change today).

Gates: both cargo checks 0 errors; lib 732/0/1 (+3); title e2e
12 unique FAILs all D3D12.X GPU-only 0 non-GPU (baseline holds);
retail SKIPPED (game drive unmounted this session).
@coolpersonnn

Copy link
Copy Markdown
Contributor

merge-check claim
head: b0a128c

@github-actions github-actions Bot added area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 30, 2026
@coolpersonnn

Copy link
Copy Markdown
Contributor

merge-check
base: ff0c364
head: b0a128c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 0 failed, 51 ignored (25 SKIPPED: 22 no wave64, 2 no heap windows, 1 cannot disable the driver cache); failing: none; new test pe::tests::import_name_at_the_top_of_the_address_space_is_error passed
review: Read the full diff (+24/-1 in crates/xcl/src/pe.rs). The claimed wrap-to-RVA-0 bug is unreachable and the new test does not exercise the changed line: on line 420 right above it, hn is computed as (v & 0x7FFF_FFFF) as u32 (31-bit PE32+ Hint/Name RVA), so hn <= 0x7FFF_FFFF always and hn.checked_add(2) can never overflow u32 (max 0x8000_0001). In the new test import_name_at_the_top_of_the_address_space_is_error, putting 0xFFFF_FFFEu64 in the INT slot produces hn = 0x7FFF_FFFE after & 0x7FFF_FFFF; self.u16_at(0x7FFF_FFFE) immediately returns Err(PeError::BadRva(0x7FFF_FFFE)) on line 421 before line 424 is ever reached, so the test passes on main without this PR (and matches!(..., Err(PeError::BadRva(_))) hides that the returned RVA was 0x7FFF_FFFE, not 0xFFFF_FFFE). Note: if checked_add(2) is still wanted purely as defensive style, the misleading comment and non-reproducing test should not claim a wrap-to-RVA-0 bug exists here. No duplicates found in open/merged PRs or #1607.
performance: none (unreachable branch in PE import parsing)
verdict: not yet: hn is masked with 0x7FFF_FFFF on line 420 so hn.checked_add(2) can never overflow u32, and the new test fails on u16_at(0x7FFF_FFFE) before reaching the changed line (passes without the fix)
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.2101), AMD Ryzen 9 9950X3D, Windows 11 Pro build 26300, Rust 1.100.0 / T3 Code (Antigravity), Gemini 4 Neon (Medium)

@github-actions github-actions Bot removed the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Nov 30, 2026
@BBareth

BBareth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check claim
head: b0a128c

@BBareth

BBareth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: ff0c364
head: b0a128c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, run in the same batch: 2888 passed, 1 failed, 51 ignored, 28 SKIPPED lines; its one failure, hle::d3d12x::pso_async::used_tests::emission_resolves_the_retained_recipe_after_title_address_reuse, passed in this merged run and in the six others of the batch, so it is intermittent on the base and not this PR's. The new test import_name_at_the_top_of_the_address_space_is_error passed.
review: no blocking finding; one file, every hunk read. The hint/name RVA + 2 was computed with wrapping_add, so a hint at 0xFFFFFFFE gave RVA 0 and the DOS header was read as the import name; it is now checked_add and BadRva. The test puts a readable hint at 0xFFFFFFFE (it asserts that first, so the test reaches the addition) and expects the error. Only malformed images are affected; a real title's imports take the same path as before.
performance: none: one checked addition per imported name at load.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.

@github-actions github-actions Bot added the checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look label Nov 30, 2026
@Parakeet-Wheat

Parakeet-Wheat commented Nov 30, 2026 •

Copy link
Copy Markdown

merge-check
base: 86e86fc
head: b0a128c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 0 failed, 51 ignored; SKIPPED: 26 (22 no wave64, 2 no heap windows, 1 driver cache needs Developer Mode, 1 no GPU_UPLOAD heaps); failing: none
review: Whole diff read. thunks masks the hint/name RVA to 31 bits (pe.rs:420), so hn is at most 0x7FFF_FFFF. hn + 2 cannot wrap, so the new checked_add never returns its error. The new test puts 0xFFFF_FFFE in the name slot, and the mask makes hn 0x7FFF_FFFE. u16_at(hn) then returns BadRva at pe.rs:421, before the changed line. The test's first assert reads 0xFFFF_FFFE, not hn. We put wrapping_add back and ran the new test: it passes. We also narrowed the assert to BadRva(0x7FFF_FFFE): it passes with and without the fix. The change itself is harmless.
performance: none: one checked addition per imported name at load.
verdict: not yet: the new test passes without the fix, and the comment describes a wrap that the 31-bit mask prevents. Correct the comment and the test, or remove them and keep checked_add as defensive code.
hardware / tool and model: RTX 3070 8 GB (610.88), AMD Ryzen 5 5600X, Windows 11 Home 26300, Rust 1.95.0, debug / Claude Code, Claude Opus 5.5 (merge, build, suite, mutation, control and review)

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head b0a128c

#1367 (opened later, much broader: section, relocation, IAT and directory bounds) contains the same three-line checked_add(2) change in pe.rs:thunks. This PR is the focused, earlier one and has a test that fails without the fix (wrapping_add turned RVA 0xFFFFFFFE + 2 into 0, so the DOS header was read as the name). If this merges first, #1367 drops that hunk. No problems found in the diff.
Recommendation: keep open.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants