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

Closed
github-bot wants to merge 1 commit from gh-pr/727/head into gh-pr/727/base
Owner

@⁠faizanzatro on GitHub · 2026-11-24 04:09 UTC · original
faizanzatro:fix/pe-export-ordinal-overflow → main · +22 −1 · 1 files · 1 commits · closed without merging

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.
**@⁠faizanzatro** on GitHub · 2026-11-24 04:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/727) `faizanzatro:fix/pe-export-ordinal-overflow` → `main` · +22 −1 · 1 files · 1 commits · closed without merging 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:40 +00:00
github-bot closed this pull request 2026-11-26 04:30:40 +00:00
Author
Owner

@⁠faizanzatro on GitHub · 2026-11-24 04:14 UTC · original

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

**@⁠faizanzatro** on GitHub · 2026-11-24 04:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/727#issuecomment-7121837542) Closing in favor of earlier draft PR #700 by @⁠towiice.
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 04:15 UTC · original

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.
**@⁠lordon1a** on GitHub · 2026-11-24 04:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/727#issuecomment-7121856819) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.