[pr-fix] pe: import-library members that are not AMD64 are refused #407

Manually merged
TrustNo1 merged 1 commit from qnjk/Darner:implib-machine-check into main 2026-12-05 04:50:33 +00:00
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: crates/darner-pe/src/implib.rs feeds every archive member to object's short-format import reader and keeps whatever comes back, without ever reading the header's machine field:

    match ImportFile::parse(bytes) {
        Ok(import) => lib.imports.push(LibImport {
            dll: String::from_utf8_lossy(import.dll()).into_owned(),
            ...
    

    (implib.rs:43-55). object 0.41.0 exposes that field as ImportFile::architecture() (object-0.41.0/src/read/coff/import.rs:70-78); nothing read it. A member from the SDK's um\x86 or um\arm64 therefore parsed as if it were the console's export map, and its decorated names landed beside the real ones with nothing to tell them apart. On the PE path the same crate already refuses a foreign machine (image.rs:139-143, machine != MACHINE_AMD64), so this was the one reader in the crate that did not.

  • This change refuses a member whose architecture is not x86-64, failing the library with PeError::Unsupported("import library member for I386 is not AMD64") — the same variant and the same shape of message the image path uses. The accepting arm is untouched; the diff is additions only.

How it was tested

  • Tested revision: 8182918 (one commit on f3840d7).
  • Commands and results:
    • cargo test --locked -p darner-pe --lib — 37 passed, 0 failed.
    • New test implib::tests::an_import_object_of_another_machine_is_refused: it builds the existing synthetic archive with one AMD64 ExitProcess member and one member whose machine field is rewritten to IMAGE_FILE_MACHINE_I386 (0x014c) and which holds _ExitProcess@4, then asserts the parse is Err(PeError::Unsupported(..)) and that the message names I386.
    • Fail-before, with only the guard arm removed and the test kept:
      thread 'implib::tests::an_import_object_of_another_machine_is_refused' panicked at
      crates\darner-pe\src\implib.rs:580:22:
      a foreign import object must be refused, got Ok(ImportLibrary { imports: [
        LibImport { dll: "kernel32.dll", export: Name { hint: 0, name: "ExitProcess" }, kind: Code },
        LibImport { dll: "kernel32.dll", export: Name { hint: 0, name: "_ExitProcess@4" }, kind: Code }],
        other_members: 0 })
      
      The bogus _ExitProcess@4 beside ExitProcess is exactly the duplicate the finding measured against a real um\x86\MSTask.Lib.
    • cargo clippy --locked -p darner-pe --all-targets -- -D warnings passes.
  • Changes a default: no. Every AMD64 import library parses exactly as before; a library that contains a member of another machine is now an error instead of being read with the wrong names.
  • A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not green on this machine, and not because of this change. Three pre-existing failures, each covered by an open pull request: darner-gpu stands still in parallel on the test deadlock #224 describes, and serially finishes 1772 passed and 1 failed (pipeline::make::tests::a_capped_draw_waits_once_then_drops, which passes on its own) beside the order-dependent watch::tests::ask_once_by_res_splits_reservations_without_refusals and texture::ahead::tests::drain_waits_until_then_callbacks_have_run flakes of #150; darner-shader fails emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, whose fixture #227 fixes. darner-pe's own suite is green (37 passed).
  • Gameplay, when relevant: not applicable. This reader serves darner lib-exports and the loader's import-library analysis; it never runs while the title runs.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: only the I386 case is exercised; ARM64/ARMNT/Unknown go through the same single architecture() comparison and are untested but code-identical. The CLI path (apps/darner/src/inspect.rs, lib_exports) has no test and none was added — the change is in darner-pe. The test writes the machine field at its header offset rather than through object; a wrong offset would fail the assertion loudly rather than pass silently.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: this is import-library analysis for the darner lib-exports/census tools, not a runtime path. The evidence is the new test, which fails on main.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 555 files ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. No open pull request changes crates/darner-pe/src/implib.rs or inspect.rs (checked against the file list of all 161 open pull requests), and no open or closed issue mentions implib, lib-exports or import libraries.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `crates/darner-pe/src/implib.rs` feeds every archive member to `object`'s short-format import reader and keeps whatever comes back, without ever reading the header's machine field: ```rust match ImportFile::parse(bytes) { Ok(import) => lib.imports.push(LibImport { dll: String::from_utf8_lossy(import.dll()).into_owned(), ... ``` (`implib.rs:43-55`). `object` 0.41.0 exposes that field as `ImportFile::architecture()` (`object-0.41.0/src/read/coff/import.rs:70-78`); nothing read it. A member from the SDK's `um\x86` or `um\arm64` therefore parsed as if it were the console's export map, and its decorated names landed beside the real ones with nothing to tell them apart. On the PE path the same crate already refuses a foreign machine (`image.rs:139-143`, `machine != MACHINE_AMD64`), so this was the one reader in the crate that did not. - This change refuses a member whose architecture is not x86-64, failing the library with `PeError::Unsupported("import library member for I386 is not AMD64")` — the same variant and the same shape of message the image path uses. The accepting arm is untouched; the diff is additions only. ## How it was tested - Tested revision: `8182918` (one commit on `f3840d7`). - Commands and results: - `cargo test --locked -p darner-pe --lib` — 37 passed, 0 failed. - New test `implib::tests::an_import_object_of_another_machine_is_refused`: it builds the existing synthetic archive with one AMD64 `ExitProcess` member and one member whose machine field is rewritten to `IMAGE_FILE_MACHINE_I386` (`0x014c`) and which holds `_ExitProcess@4`, then asserts the parse is `Err(PeError::Unsupported(..))` and that the message names `I386`. - Fail-before, with only the guard arm removed and the test kept: ``` thread 'implib::tests::an_import_object_of_another_machine_is_refused' panicked at crates\darner-pe\src\implib.rs:580:22: a foreign import object must be refused, got Ok(ImportLibrary { imports: [ LibImport { dll: "kernel32.dll", export: Name { hint: 0, name: "ExitProcess" }, kind: Code }, LibImport { dll: "kernel32.dll", export: Name { hint: 0, name: "_ExitProcess@4" }, kind: Code }], other_members: 0 }) ``` The bogus `_ExitProcess@4` beside `ExitProcess` is exactly the duplicate the finding measured against a real `um\x86\MSTask.Lib`. - `cargo clippy --locked -p darner-pe --all-targets -- -D warnings` passes. - Changes a default: no. Every AMD64 import library parses exactly as before; a library that contains a member of another machine is now an error instead of being read with the wrong names. - A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: **not green on this machine, and not because of this change.** Three pre-existing failures, each covered by an open pull request: `darner-gpu` stands still in parallel on the test deadlock #224 describes, and serially finishes 1772 passed and 1 failed (`pipeline::make::tests::a_capped_draw_waits_once_then_drops`, which passes on its own) beside the order-dependent `watch::tests::ask_once_by_res_splits_reservations_without_refusals` and `texture::ahead::tests::drain_waits_until_then_callbacks_have_run` flakes of #150; `darner-shader` fails `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, whose fixture #227 fixes. `darner-pe`'s own suite is green (37 passed). - Gameplay, when relevant: not applicable. This reader serves `darner lib-exports` and the loader's import-library analysis; it never runs while the title runs. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: only the I386 case is exercised; ARM64/ARMNT/`Unknown` go through the same single `architecture()` comparison and are untested but code-identical. The CLI path (`apps/darner/src/inspect.rs`, `lib_exports`) has no test and none was added — the change is in `darner-pe`. The test writes the machine field at its header offset rather than through `object`; a wrong offset would fail the assertion loudly rather than pass silently. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: this is import-library analysis for the `darner lib-exports`/`census` tools, not a runtime path. The evidence is the new test, which fails on `main`. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 555 files ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. No open pull request changes `crates/darner-pe/src/implib.rs` or `inspect.rs` (checked against the file list of all 161 open pull requests), and no open or closed issue mentions `implib`, `lib-exports` or import libraries. - Replaces or overlaps: none found
The member loop of `ImportLibrary::parse` kept whatever `object`'s
short-format import reader returned and never read the header's machine
field, so a member from `um\x86` or `um\arm64` parsed as if it were the
console's export map: its `_ExitProcess@4` landed beside the real
`ExitProcess` of the same DLL, with nothing to tell them apart.

`image.rs` refuses a foreign machine for a PE image; this is the one
reader in the crate that did not. A member whose architecture is not
x86-64 now fails the library with `PeError::Unsupported`, the same
variant and the same shape of message the image path uses.

The test builds the existing synthetic archive with one AMD64 member and
one whose machine field is `IMAGE_FILE_MACHINE_I386`; on main the I386
member is merged, here it is refused.
TrustNo1 manually merged commit cbbec58a90 into main 2026-12-05 04:50:33 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
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.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!407
No description provided.