Repository navigation
Description
OwnedExports::from_pe (crates/xcl/src/pe.rs) adds the export directory's Base, read from the file, to each function index with plain u32 addition:
out.by_ordinal.insert(ex.ordinal_base + i as u32, t);With a Base near u32::MAX this panics with an overflow in debug builds. The loader calls it for every mapped game DLL (loader.rs:133, OwnedExports::from_pe(&pe).unwrap_or_default()), so unwrap_or_default does not help. In release builds the sum wraps to low ordinals, and the entry can shadow a real ordinal 0, 1, … The rest of pe.rs already uses checked arithmetic for values from the file (#106). This one was missed.
Only a malformed or unusual export table hits this. Valid images keep Base + NumberOfFunctions inside 16 bits.
Failing test (in pe.rs's mod tests, uses the existing directory_at_rva helper):
/// The ordinal base comes from the file: an export past u32::MAX is no ordinal and is skipped
/// (it panicked on overflow in debug builds and wrapped to ordinal 0 in release ones).
#[test]
fn export_ordinals_past_u32_max_are_skipped() {
let rva = 0x1000u32;
let mut payload = vec![0u8; 48];
payload[16..20].copy_from_slice(&u32::MAX.to_le_bytes()); // Base
payload[20..24].copy_from_slice(&2u32.to_le_bytes()); // NumberOfFunctions
payload[28..32].copy_from_slice(&(rva + 40).to_le_bytes()); // AddressOfFunctions
payload[40..44].copy_from_slice(&0x2000u32.to_le_bytes());
payload[44..48].copy_from_slice(&0x2004u32.to_le_bytes());
let data = directory_at_rva(DIR_EXPORT, rva, &payload);
let pe = Pe::parse(&data, Layout::File).unwrap();
let ex = OwnedExports::from_pe(&pe).unwrap();
assert_eq!(ex.by_ordinal.len(), 1);
assert_eq!(ex.by_ordinal.get(&u32::MAX), Some(&ExportTarget::Rva(0x2000)));
assert!(!ex.by_ordinal.contains_key(&0));
}On main (91f9a5e): cargo test -p xcl --lib pe::tests::export fails with attempt to add with overflow at crates\xcl\src\pe.rs:610:43.
Proposed fix: skip entries past u32::MAX and keep the others:
for (i, &rva) in ex.functions.iter().enumerate() {
+ // the base comes from the file: an entry past u32::MAX has no ordinal
+ let Some(ordinal) = ex.ordinal_base.checked_add(i as u32) else { break };
if let Some(t) = pe.export_target(&ex, rva) {
- out.by_ordinal.insert(ex.ordinal_base + i as u32, t);
+ out.by_ordinal.insert(ordinal, t);
}
}With the fix: cargo test -p xcl --lib -- --test-threads=4 gave 653 passed, 0 failed, 21 ignored (652 on main without the new test).
Tested
- i7-12700H, Intel Iris Xe + RTX 3070 Ti Laptop, Windows 11 build 26200
- rustc 1.100.0,
x86_64-pc-windows-gnullvm, debug. This is not the MSVC toolchain the project uses. - Only
--libtests were run.
Not tested
cargo test --workspace(integration, e2e and GPU tests), the MSVC toolchainscripts/smoke.ps1: I have no title to run it on. The fix is a runtime change, so a PR needs someone with a title for the twoxcl-smokeblocks. Branch with the test and the fix (one commit on91f9a5e): https://github.com/lordon1a/xcl/tree/pe-export-ordinal-overflow
AI use
- Claude Code, Claude Opus 5.5: found the bug, wrote the test and the fix, wrote this issue. I checked the test failing and passing myself.
Activity
Anon64 commentedon Nov 24, 2026
Test report for the branch
lordon1a/xclpe-export-ordinal-overflowat88311e4, which is based onmain91f9a5e: the MSVC toolchain, the whole workspace, and the two regression runs. If you open the PR from this commit, you can paste both blocks into Regression run.Tested
x86_64-pc-windows-msvccargo test --workspace --no-fail-fast -- --test-threads=4(debug) on88311e4: 692 passed, 1 failed, 41 ignored.pe::tests::export_ordinals_past_u32_max_are_skippedpasses. The one failure ishle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory, which fails the same way onmainon this machine (Tests: align XMemVirtualQuery buffers and verify CPU flags #650 / Tests: align the XMemVirtualQuery output buffer #656).checked_addchange the new test panics:attempt to add with overflowatcrates\xcl\src\pe.rs:611:43SKIPPED:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64)Regression run (
scripts/smoke.ps1, release, same title, 60 s each; pasted unedited)main:
88311e4:Not tested
Report written with Claude Code (Claude Opus 5.5) from runs on this machine.
towiice commentedon Nov 24, 2026
PR with the fix and the test from this issue, rebased on current main: #700 (draft until someone with a title adds the
xcl-smokeblocks — I have none). Claude Code (Claude Sonnet 5.5).PE loader: skip export ordinals past u32::MAX (xcl-dev#691)