PE loader: skip export ordinals that overflow u32::MAX (#691) #722

Closed
faizanzatro wants to merge 1 commit from upstream-pr/727 into main
faizanzatro commented 2026-11-24 04:09:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by faizanzatro on 2026-11-24T04:09:06Z.


Fixes #691.

What is in it

OwnedExports::from_pe in crates/xcl/src/pe.rs previously added ex.ordinal_base to the function loop index i as u32 using unchecked arithmetic. When parsing a crafted or malformed PE image where ordinal_base is close to u32::MAX, this caused an integer overflow panic in debug builds and wrapped around to shadow low ordinals (such as ordinal 0) in release builds.

This fix:

  • Uses ex.ordinal_base.checked_add(i as u32) when inserting into out.by_ordinal.
  • Stops processing when the ordinal overflows u32::MAX (entries past u32::MAX cannot be valid 32-bit ordinals).
  • Adds unit test export_ordinals_past_u32_max_are_skipped verifying that ordinals at u32::MAX are preserved while overflowing ones are skipped without panicking or wrapping.

Tested

  • Windows 11 x64, rustc 1.94.1 (MSVC), Windows SDK (DXC)
  • cargo test -p xcl --lib pe::: 11 passed, 0 failed
  • cargo test --workspace -- --test-threads=4: 682 passed, 0 failed, 41 ignored (2 GPU tests skipped: no wave64)
  • .\scripts\test.ps1: all workspace builds and tests pass cleanly

Not tested

  • macOS / Linux (Windows MSVC only project)

AI use

  • Google Antigravity (Gemini 2.5 Pro): verified issue report #691, reviewed PE parsing logic, verified unit tests on Windows 11.
<!-- greyfinch-sync:ivall/xcl:issue:6574403237 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/727). Originally posted by [faizanzatro](https://github.com/faizanzatro) on 2026-11-24T04:09:06Z. --- Fixes #691. ### What is in it `OwnedExports::from_pe` in `crates/xcl/src/pe.rs` previously added `ex.ordinal_base` to the function loop index `i as u32` using unchecked arithmetic. When parsing a crafted or malformed PE image where `ordinal_base` is close to `u32::MAX`, this caused an integer overflow panic in debug builds and wrapped around to shadow low ordinals (such as ordinal 0) in release builds. This fix: - Uses `ex.ordinal_base.checked_add(i as u32)` when inserting into `out.by_ordinal`. - Stops processing when the ordinal overflows `u32::MAX` (entries past `u32::MAX` cannot be valid 32-bit ordinals). - Adds unit test `export_ordinals_past_u32_max_are_skipped` verifying that ordinals at `u32::MAX` are preserved while overflowing ones are skipped without panicking or wrapping. **Tested** - Windows 11 x64, rustc 1.94.1 (MSVC), Windows SDK (DXC) - `cargo test -p xcl --lib pe::`: 11 passed, 0 failed - `cargo test --workspace -- --test-threads=4`: 682 passed, 0 failed, 41 ignored (2 GPU tests skipped: no wave64) - `.\scripts\test.ps1`: all workspace builds and tests pass cleanly **Not tested** - macOS / Linux (Windows MSVC only project) **AI use** - Google Antigravity (Gemini 2.5 Pro): verified issue report #691, reviewed PE parsing logic, verified unit tests on Windows 11.
upstream-sync closed this pull request 2026-11-24 06:59:41 +00:00
copilot-pull-request-reviewer[bot commented 2026-11-24 06:59:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T04:09:21Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ivall/xcl:review:6033514496 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/727#pullrequestreview-6033514496). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-24T04:09:21Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
faizanzatro commented 2026-11-24 07:06:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by faizanzatro on 2026-11-24T04:14:31Z.


Closing in favor of earlier draft PR #700 by @towiice.

<!-- greyfinch-sync:ivall/xcl:comment:7121837542 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/727#issuecomment-7121837542). Originally posted by [faizanzatro](https://github.com/faizanzatro) on 2026-11-24T04:14:31Z. --- Closing in favor of earlier draft PR #700 by @towiice.
lordon1a commented 2026-11-24 07:06:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by lordon1a on 2026-11-24T04:15:45Z.


Independent test report on da7a9bd:

Tested

  • Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver 616.64, wave32, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), rustc 1.100.0 (x86_64-pc-windows-gnullvm), debug build, DXC 1.9.2609.5 (01b62ad4)
  • Command: cargo test -p xcl --lib pe::tests -- --nocapture
  • Result: 11 passed, 0 failed, 0 ignored in 0.06s (export_ordinals_past_u32_max_are_skipped ok)

Not tested

  • AMD / wave64, Intel GPU, retail title (xcl-smoke)

AI use

  • Antigravity (Google DeepMind agent) — fetched da7a9bd in a detached worktree, audited the diff, ran the test suite, and posted this report.
<!-- greyfinch-sync:ivall/xcl:comment:7121856819 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/727#issuecomment-7121856819). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T04:15:45Z. --- Independent test report on `da7a9bd`: **Tested** - Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver `616.64`, wave32, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), `rustc 1.100.0` (`x86_64-pc-windows-gnullvm`), debug build, DXC `1.9.2609.5` (`01b62ad4`) - Command: `cargo test -p xcl --lib pe::tests -- --nocapture` - Result: **11 passed, 0 failed, 0 ignored** in `0.06s` (`export_ordinals_past_u32_max_are_skipped` ok) **Not tested** - AMD / wave64, Intel GPU, retail title (`xcl-smoke`) **AI use** - Antigravity (Google DeepMind agent) — fetched `da7a9bd` in a detached worktree, audited the diff, ran the test suite, and posted this report.

Pull request closed

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!722
No description provided.