PE loader: avoid overflow when computing export ordinals #1524

Closed
ORKHANALIYEV27 wants to merge 1 commit from upstream-pr/1534 into main
ORKHANALIYEV27 commented 2026-11-24 17:21:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ORKHANALIYEV27 on 2026-11-24T17:21:10Z.


PE loader: avoid overflow when computing export ordinals

Fixes #691. In OwnedExports::from_pe, ex.ordinal_base + i as u32 overflowed
in debug (panic) or wrapped in release when a PE's export ordinal base was near
u32::MAX. Use checked_add and skip the entry on overflow.

What is in it

  • crates/xcl/src/pe.rs: checked addition in the export-ordinal loop

Tested

  • cargo check -p xcl (MSVC toolchain unavailable in this environment; checked with the
    GNU toolchain: compiles; the GNU test binary lacks a TLS directory so
    parses_own_test_binary_tls is pre-existing-environmental and unrelated)

Not tested

  • MSVC build and the full test suite on Windows

AI use

  • Claude Code (Beam) wrote the change and this description
<!-- greyfinch-sync:ivall/xcl:issue:6587481300 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1534). Originally posted by [ORKHANALIYEV27](https://github.com/ORKHANALIYEV27) on 2026-11-24T17:21:10Z. --- PE loader: avoid overflow when computing export ordinals Fixes #691. In `OwnedExports::from_pe`, `ex.ordinal_base + i as u32` overflowed in debug (panic) or wrapped in release when a PE's export ordinal base was near `u32::MAX`. Use `checked_add` and skip the entry on overflow. **What is in it** - `crates/xcl/src/pe.rs`: checked addition in the export-ordinal loop **Tested** - `cargo check -p xcl` (MSVC toolchain unavailable in this environment; checked with the GNU toolchain: compiles; the GNU test binary lacks a TLS directory so `parses_own_test_binary_tls` is pre-existing-environmental and unrelated) **Not tested** - MSVC build and the full test suite on Windows **AI use** - Claude Code (Beam) wrote the change and this description
dcastell1 commented 2026-11-24 18:09:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by dcastell1 on 2026-11-24T17:24:30Z.


Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@9e3831e (baseline 776 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
776 passed; 0 failed; 41 ignored   (exit 0)

Same count as the baseline (the overflow guard is exercised by existing export/import coverage), nothing regresses.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

<!-- greyfinch-sync:ivall/xcl:comment:7139148688 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1534#issuecomment-7139148688). Originally posted by [dcastell1](https://github.com/dcastell1) on 2026-11-24T17:24:30Z. --- Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on `main@9e3831e` (baseline **776 passed, 0 failed, 41 ignored** on this box): ``` patch -p1 < this PR # clean, no fuzz cargo test --workspace -- --test-threads=4 776 passed; 0 failed; 41 ignored (exit 0) ``` Same count as the baseline (the overflow guard is exercised by existing export/import coverage), nothing regresses. Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
DavidM1911 commented 2026-11-24 19:07:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T19:05:55Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7141594175 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1534#issuecomment-7141594175). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T19:05:55Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. Thanks!
upstream-sync closed this pull request 2026-11-24 21:06:27 +00:00
throny commented 2026-11-24 21:08:59 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-24T19:38:16Z.


Two contributors checked independently and found that this PR makes the same change as #700 (for #691): #1607, group D16. They suggest keeping #700. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps.

This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

<!-- greyfinch-sync:ivall/xcl:comment:7142379478 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1534#issuecomment-7142379478). Originally posted by [throny](https://github.com/throny) on 2026-11-24T19:38:16Z. --- <!-- xcl-1607-hint:D16 --> Two contributors checked independently and found that this PR makes the same change as #700 (for #691): #1607, group D16. They suggest keeping #700. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps. This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
ivall commented 2026-11-24 21:09:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-24T20:42:43Z.


Closing this as a duplicate: #700 makes the same change and was opened first (an export ordinal past u32::MAX is skipped with a checked add). It stays open and is the one that will be reviewed and merged.

This says nothing about the quality of the code here. I compared the two diffs; the pair was also found by independent checks in #1607. If this PR covers a case #700 does not, or #700 is closed without being merged, say so and I'll reopen it. A test that is only here is welcome on #700.

Thank you for the work.

AI use: Claude Code (Claude Opus 5.5) compared the diffs and wrote this comment; the decision is the maintainer's.

<!-- greyfinch-sync:ivall/xcl:comment:7143954040 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1534#issuecomment-7143954040). Originally posted by [ivall](https://github.com/ivall) on 2026-11-24T20:42:43Z. --- Closing this as a duplicate: #700 makes the same change and was opened first (an export ordinal past u32::MAX is skipped with a checked add). It stays open and is the one that will be reviewed and merged. This says nothing about the quality of the code here. I compared the two diffs; the pair was also found by independent checks in #1607. If this PR covers a case #700 does not, or #700 is closed without being merged, say so and I'll reopen it. A test that is only here is welcome on #700. Thank you for the work. AI use: Claude Code (Claude Opus 5.5) compared the diffs and wrote this comment; the decision is the maintainer's.

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