PE: keep every name for a shared export ordinal #555

Merged
Quat3rnion merged 1 commit from upstream-pr/555 into main 2026-11-25 00:11:38 +00:00
Quat3rnion commented 2026-11-24 04:50:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T04:50:14Z.


What

ImageInfo::parse used the PE-specific export table, which keeps one name
per address-table slot. When two names aliased one ordinal, the earlier name
was silently dropped from ImageInfo::exports and from victory inspect --exports. The generic Object::exports iterator yields every named export
(and then ordinal-only entries), so the parser now uses it and maps its
target and flags back to our representation. A synthetic PE with two names
for one ordinal plus a separate export covers the alias case.

An AI tool wrote part of this change.

Tested

  • Linux: cargo test --workspace: 165 passed, 0 failed, 3 ignored. The new regression asserts all three names and their RVAs survive parsing.
  • Windows cross-build: cargo check --target x86_64-pc-windows-gnu --workspace --tests passes. No Windows host here.
  • cargo xtask policy passes (150 files ok). No game files or data from them were added.

Checklist

  • Workspace tests and Windows cross-check pass.
  • cargo xtask policy passes. No game files or data from them were added.
  • AI authorship is disclosed above.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6574859820 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/555). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-24T04:50:14Z. --- ## What `ImageInfo::parse` used the PE-specific export table, which keeps one name per address-table slot. When two names aliased one ordinal, the earlier name was silently dropped from `ImageInfo::exports` and from `victory inspect --exports`. The generic `Object::exports` iterator yields every named export (and then ordinal-only entries), so the parser now uses it and maps its target and flags back to our representation. A synthetic PE with two names for one ordinal plus a separate export covers the alias case. An AI tool wrote part of this change. ## Tested - Linux: `cargo test --workspace`: 165 passed, 0 failed, 3 ignored. The new regression asserts all three names and their RVAs survive parsing. - Windows cross-build: `cargo check --target x86_64-pc-windows-gnu --workspace --tests` passes. No Windows host here. - `cargo xtask policy` passes (150 files ok). No game files or data from them were added. ## Checklist - [x] Workspace tests and Windows cross-check pass. - [x] `cargo xtask policy` passes. No game files or data from them were added. - [x] AI authorship is disclosed above.
LAKSHYA-cmd-tech commented 2026-11-24 06:53:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T04:55:44Z.

Review: APPROVED


Verified on Windows 11:

  • All 8 \ ictory-pe\ tests pass, including the new \every_name_of_a_shared_ordinal_survives\ regression test verifying that aliased export ordinals keep all names.
  • Clippy clean, asset policy passes (150 files ok).
  • The switch from PE-specific export table iteration to the generic \Object::exports\ iterator correctly preserves all names for shared ordinals.
<!-- greyfinch-sync:Marvisak/VIctory:review:6033866109 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/555#pullrequestreview-6033866109). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T04:55:44Z. **Review:** APPROVED --- Verified on Windows 11: - All 8 \ ictory-pe\ tests pass, including the new \every_name_of_a_shared_ordinal_survives\ regression test verifying that aliased export ordinals keep all names. - Clippy clean, asset policy passes (150 files ok). - The switch from PE-specific export table iteration to the generic \Object::exports\ iterator correctly preserves all names for shared ordinals.
sebastianspicker commented 2026-11-24 11:04:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sebastianspicker on 2026-11-24T11:02:09Z.


Tested b71c252 applied onto main ffe310e (macOS, Rust 1.98.1).

  • The new test fails on main exactly as described: [("beta", 1, 0x1200), ("gamma", 2, 0x1204)], so "alpha" is dropped. It passes with the PR.
  • The old code filtered Address(0) slots itself. object 0.41's PeExportIterator still skips zero addresses in its ordinal-only pass (export.rs, address == 0 => continue), and unused_export_slots_are_not_exports still passes, so the gap handling isn't lost. The only difference is a named entry pointing at a zero slot, which is malformed anyway.
  • Exports now come name-first, then bare ordinals. The only consumer I found is victory inspect --exports, so that's cosmetic.
  • cargo clippy -p victory-pe --all-targets -D warnings: clean on macOS and for x86_64-pc-windows-msvc (with -p victory).

Looks good to me.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129569038 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/555#issuecomment-7129569038). Originally posted by [sebastianspicker](https://github.com/sebastianspicker) on 2026-11-24T11:02:09Z. --- Tested `b71c252` applied onto `main` `ffe310e` (macOS, Rust 1.98.1). - The new test fails on `main` exactly as described: `[("beta", 1, 0x1200), ("gamma", 2, 0x1204)]`, so "alpha" is dropped. It passes with the PR. - The old code filtered `Address(0)` slots itself. `object` 0.41's `PeExportIterator` still skips zero addresses in its ordinal-only pass (`export.rs`, `address == 0 => continue`), and `unused_export_slots_are_not_exports` still passes, so the gap handling isn't lost. The only difference is a *named* entry pointing at a zero slot, which is malformed anyway. - Exports now come name-first, then bare ordinals. The only consumer I found is `victory inspect --exports`, so that's cosmetic. - `cargo clippy -p victory-pe --all-targets -D warnings`: clean on macOS and for `x86_64-pc-windows-msvc` (with `-p victory`). Looks good to me. AI-assisted.
mercuryVM commented 2026-11-24 12:03:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:46:19Z.

Review: APPROVED


Tested b71c252 on Windows 11, RTX 5070, MSVC: cargo test -p victory-pe 8 passed, including every_name_of_a_shared_ordinal_survives. cargo clippy -p victory-pe --all-targets is clean. victory inspect --exports on a local title executable gives the same export list before and after (identical lines, apart from unrelated output differences), so images without aliased ordinals are unaffected.

  • Moving to Object::exports keeps every name. Converting the address back to an RVA with wrapping_sub(image_base) is right, because the generic iterator adds the base.
  • The old filter for Address(0) (unused address-table slots) is gone. The generic iterator only yields named entries and ordinal entries that have a target, so gaps don't come back. Worth a one-line comment, since the old code called that out explicitly.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038612548 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/555#pullrequestreview-6038612548). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:46:19Z. **Review:** APPROVED --- Tested b71c252 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-pe` 8 passed, including `every_name_of_a_shared_ordinal_survives`. `cargo clippy -p victory-pe --all-targets` is clean. `victory inspect --exports` on a local title executable gives the same export list before and after (identical lines, apart from unrelated output differences), so images without aliased ordinals are unaffected. - Moving to `Object::exports` keeps every name. Converting the address back to an RVA with `wrapping_sub(image_base)` is right, because the generic iterator adds the base. - The old filter for `Address(0)` (unused address-table slots) is gone. The generic iterator only yields named entries and ordinal entries that have a target, so gaps don't come back. Worth a one-line comment, since the old code called that out explicitly. AI-assisted (Claude Code).
catminou4 commented 2026-11-24 13:01:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:38:19Z.

Review: APPROVED


Fixes a real data-loss bug: the PE-specific export table keeps one name per address-table slot, so two names sharing an ordinal lost all but the last. Switching to the generic file.exports() iterator yields every name (then ordinal-only entries), and the new test proves alpha+beta both survive on ordinal 1.

Checked the risky bits against object 0.41.0 sources:

  • ReadTarget::Address { address } is image-base-relative absolute; wrapping_sub(image_base) as u32 correctly recovers the RVA, and the iterator is name/ordinal-driven, so unused address-table slots (the old Address(0) filter) are never yielded.
  • The remaining ExportTarget variants (Absolute, Tls, TlsDescriptor, Resolver) are ELF/Mach-O-only — unreachable for PE, so the _ => (None, None) catch-all is dead code in practice (a debug_assert!(false) or comment wouldn't hurt, but not blocking).
  • ExportFlags::Pe { ordinal } is what the PE iterator returns; the _ => 0 fallback is likewise unreachable for PE exports.
  • Forwarders: Reexport maps library+name/ordinal to the same "dll.name"/"dll.#N" strings as before — format preserved.

Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-pe --locked (macOS arm64, rustc 1.98.1) → 4 passed / 4 failed, where the 4 failures are the pre-existing image::tests platform issue I flagged on #529 (they fail identically on unmodified main — the test binary is Mach-O, not PE). The new every_name_of_a_shared_ordinal_survives test is among the 4 passing.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039320236 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/555#pullrequestreview-6039320236). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:38:19Z. **Review:** APPROVED --- Fixes a real data-loss bug: the PE-specific export table keeps one name per address-table slot, so two names sharing an ordinal lost all but the last. Switching to the generic `file.exports()` iterator yields every name (then ordinal-only entries), and the new test proves alpha+beta both survive on ordinal 1. Checked the risky bits against `object` 0.41.0 sources: - `ReadTarget::Address { address }` is image-base-relative absolute; `wrapping_sub(image_base) as u32` correctly recovers the RVA, and the iterator is name/ordinal-driven, so unused address-table slots (the old `Address(0)` filter) are never yielded. - The remaining `ExportTarget` variants (`Absolute`, `Tls`, `TlsDescriptor`, `Resolver`) are ELF/Mach-O-only — unreachable for PE, so the `_ => (None, None)` catch-all is dead code in practice (a `debug_assert!(false)` or comment wouldn't hurt, but not blocking). - `ExportFlags::Pe { ordinal }` is what the PE iterator returns; the `_ => 0` fallback is likewise unreachable for PE exports. - Forwarders: `Reexport` maps library+name/ordinal to the same `"dll.name"`/`"dll.#N"` strings as before — format preserved. Verified locally: test-merge with current main (`ffe310e`) clean; `cargo test -p victory-pe --locked` (macOS arm64, rustc 1.98.1) → **4 passed / 4 failed**, where the 4 failures are the pre-existing `image::tests` platform issue I flagged on #529 (they fail identically on unmodified main — the test binary is Mach-O, not PE). The new `every_name_of_a_shared_ordinal_survives` test is among the 4 passing.
upstream-sync closed this pull request 2026-11-25 01:04:13 +00:00
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
Marvisak/VIctory!555
No description provided.