PE loader: a broken delay-import table fails the load #1199
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1208"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-24T13:15:14Z.
A malformed delay-import directory only logged a warning and left the module registered (and partially resolved). Normal imports already fail the load and unregister; delay-imports must do the same.
Why hard-fail (stricter than Windows)
__delayLoadHelper2first runs that entry; the image can still load.delay_imports()fails meant a partially resolved image stayed in the module list with no eager delay resolution — easy to paper over a corrupt directory until a later lazy load, and inconsistent with the normal-import path.map_image_ex.What is in it
crates/xcl/src/loader.rs: fail + unregister ondelay_imports()error; unit test with a synthetic DLL whose delay Name RVA is outside the imageTested
959e7a8959e7a829f2108ebf93c10e5f924f476df4c5549(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)cargo test -p xcl --libon RTX 3060 Ti after merging this head with currentmainlocally: all passed, 0 failed, 27 ignored. The PR head itself is unchanged.Regression run
scripts/smoke.ps1from @Toons29 (RX 9070, 60 s, same title/time; blocks as printed):Not tested
cargo test --workspaceAI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:47:22Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Note: the full
d3d12xlib filter currently aborts with 0xc0000005 on unmodifiedmaintoo (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:16:11Z.
Regression run of
959e7a82on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.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.Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-25T12:36:34Z.
Thanks @Toons29 — pasted both of your
xcl-smoke v1blocks under Regression run so the description check can see them.Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-25T12:43:56Z.
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.Imported from ivall/xcl. Originally posted by jennydeth on 2026-11-25T13:00:21Z.
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
959e7a8.Result: cargo test --workspace -- --test-threads=4: 742 passed, 0 failed, 41 ignored. SKIPPED: 2 GPU tests for no wave64 (expected on this card).
Not tested: titles that ship delay-load imports.
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-25T13:21:15Z.
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)).
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T03:52:44Z.
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
Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-26T12:33:32Z.
Thanks @DavidM1911 — noted the
cargo test -p xcl --libre-check (passed, 0 failed, 27 ignored) under Tested. Head commit is unchanged.Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T18:10:54Z.
merge-check claim
head:
959e7a829fImported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T18:23:33Z.
merge-check
base:
abec7ce9eehead:
959e7a829fmerge: clean (trial merge 5e1c7f9b4d3603d8cbe2f3935a126f2e91a3c4e3; git diff --check clean; +33/-1 in crates/xcl/src/loader.rs)
build: cargo build --workspace -> ok (39 lib + 19 test warnings, all pre-existing dead code / deprecations, none from the PR's lines)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2887 passed, 0 failed, 51 ignored (base + 1 new test; the base
abec7ce9includes #3513's resinfo-D16 test fix, so the previously failing gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 passes now — this was the only failure on this machine's earlier baseline). SKIPPED: 27, the standard set for this card (22 "no wave64" — wave32-only GPU, 2 "no heap windows", 1 "cannot disable the driver cache (Developer Mode)", 2 "no xgameruntime.dll"). The new a_dll_with_a_broken_delay_import_table_is_not_left_registered passes in the targeted loader run (5/0) and inside the full suite.review: read the whole diff and the surrounding code. In map_image_ex a parse failure of pe.delay_imports() only logged a warning and continued the load, leaving the mapped module registered; the module's own comment (loader.rs 160-162) promises "a failure from here on takes the module out of the registry again", and the import-table path honours it (unregister + fail) but the delay path did not. The consequence: load_game_dll's idempotency check (find_mapped_by_name) would later return the half-initialised module — delay imports unresolved, module handles not written — as "already loaded", and the address-range lookup would hit it too. The fix makes the delay path identical to the import-table path: unregister_mapped(base) then fail(...). I checked the two helpers: fail frees the mapped memory (VirtualFree MEM_RELEASE) and returns Err, and unregister_mapped removes the module from both the name registry and the lock-free range table (modules.rs:140, documented as Windows' behaviour for a failed DLL), so nothing leaks and no stale entry survives. At the point delay_imports() fails the normal imports have been parsed but not resolved (resolution starts after both parses), so unregistering there is exactly as safe as on the import-table failure. The parser side is already bounded (pe.rs:455-488: at most 4096 descriptors, checked arithmetic, a name RVA outside the image answers BadRva via cstr_at). The test builds a DLL with the existing tiny_dll helper whose delay directory (#13 of 16 data directories, at the helper's computed offset 0x58+0x70+13*8) points at a descriptor with attrs=1 (RVA-based) and Name=0x7FFF0000 outside the image, so the parse errors; it then asserts load_game_dll fails with a "delay-import table" message and find_mapped_by_name is None, over two attempts — the second attempt is what fails under the old behaviour, which would return the still-registered module. The zeroed second descriptor at 0x1030 terminates the parse loop (name_rva == 0 && iat_rva == 0). Thread: DavidM1911 on an RTX 3060 Ti — cargo test -p xcl --lib loader 3/0 at the head merged with current main, plus a re-verification (cargo test -p xcl --lib all passed, 0 failed, 27 ignored); jennydeth on an RTX 3060 — cargo test --workspace 742 passed, 0 failed, 41 ignored, 2 wave64 SKIPPED; Toons29's paired retail xcl-smoke on an RX 9070 (main
4178e888vs this head: 101% of main's frames, 100% of its peak commit, 0 crashes, 0 device removals). Overlap note: #1367 (open, not in the queue — red CI) "PE: validate directory and table bounds in parser and loader" is complementary, not a duplicate: it hardens the parser (more malformed shapes answer BadRva) and bounds-checks the IAT / module-handle writes in the resolution loop, a different hunk; if it lands first, this PR's error path simply fires for more shapes. No #1607 duplicate group covers #1208. One file, no new dependencies, no stop-criteria files.performance: none; the success path is unchanged, only the already-failing path now fails and frees its mapping instead of continuing with a half-initialised module registered.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B
Imported from ivall/xcl. Originally posted by coolpersonnn on 2026-11-30T18:33:48Z.
merge-check claim
head:
959e7a829fImported from ivall/xcl. Originally posted by coolpersonnn on 2026-11-30T18:39:15Z.
merge-check
base:
abec7ce9eehead:
959e7a829fmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2887 passed, 0 failed, 51 ignored (25 SKIPPED: 22 no wave64, 2 no heap windows, 1 cannot disable the driver cache); failing: none; new test loader::tests::a_dll_with_a_broken_delay_import_table_is_not_left_registered passed
review: none. Read the full diff (+33/-1 in crates/xcl/src/loader.rs). In map_image_ex, pe.delay_imports() returning Err now unregisters the mapped base and calls fail(...) (freeing the mapping and returning Err), matching pe.imports() right above it before any imports are resolved against the module. The new unit test builds a synthetic DLL with data directory #13 pointing to a delay-import descriptor whose Name RVA is outside the image, runs load_game_dll twice, and verifies both attempts fail with "delay-import table" and leave nothing registered (would fail before the fix, since the old code only logged a warning and kept loading). Minimal scope; no duplicates found in open/merged PRs or #1607.
performance: none (error path during DLL loading only; no hot-path or memory overhead)
verdict: safe to merge
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)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:07:39Z.
Triage (#1607) – head
959e7a8No open or merged PR makes the same change (#1367 bounds the delay-load module-handle write but still only warns when the delay-import table does not parse). One point to consider in loader.rs:map_image_ex: until now a delay-import table that XCL's parser rejects only skipped eager resolution, and the image's own
__delayLoadHelper2thunks still loaded lazily. With this change the whole module fails to load, which is stricter than Windows (it reports a broken delay descriptor only on the first call). The PR description should say why a hard failure is preferred.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Longno242 on 2026-12-02T20:47:23Z.
Updated the description for @Foniass's triage note: why we hard-fail a broken delay-import table at load (same as normal imports) instead of Windows' defer-until-first-helper behavior.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.