PE loader: saturate TlsDir::total_len and bound rva_to_offset in Layout::File #1397
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1397
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1397"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@b3IKK on GitHub · 2026-11-24 15:34 UTC · original
b3IKK:pe/tls-len-and-rva-file-bounds→main· +43 −3 · 1 files · 1 commits · openFixes two bounds/overflow bugs in
crates/xcl/src/pe.rs:TlsDir::total_lenaddedself.template_len() + self.size_of_zero_fill as u64without saturating, panicking in debug or wrapping in release whenend_raw - start_rawis nearu64::MAX.Pe::rva_to_offsetinLayout::FilereturnedSome(rva as usize)(for headers) orSome(s.raw_ptr as usize + delta as usize)(for sections) without checking that the offset lies withinself.data.len(), unlikeLayout::Mapped.This uses
saturating_addinTlsDir::total_lenand checksoff < self.data.len()(with checked addition) inLayout::File.What is in it
crates/xcl/src/pe.rs: saturateTlsDir::total_len; bounds-checkLayout::Fileoffsets inPe::rva_to_offset; add unit teststls_dir_total_len_saturates_instead_of_overflowingandrva_to_offset_in_file_layout_rejects_offsets_past_eof(including exactraw_ptr + delta == data.len()boundary check; both verified failing before the fix).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 753 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib pe::tests: 12 passed, 0 failed (both new tests failed before the fix)Regression run
main:
PR:
Not tested
AI use
pe.rs, wrote the fixes and unit tests, added the exactraw_ptr + delta == data.len()boundary assertion per review feedback, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.@pickles976 on GitHub · 2026-11-24 15:37 UTC · original
Review: correct and well-scoped —
saturatingTLStotal_lenkills the wrap-to-small-length case (allocation sized from the overflowed value), and boundingrva_to_offsetatraw_ptr + delta >= data.len()is the consumer-side half of the parse-time invariant I proposed in #836; the truncated-image test is exactly the right regression harness. One edge row worth adding while the test is fresh:raw_ptr + deltalanding exactly ondata.len()— the message already specifies>=so the implementation reads right, but pinning the boundary value makes a future off-by-one regression fail loudly. Combined with #1367 (parser-side directory validation), this pair implements the full invariant: five independent finds across three loaders today were all instances of these two gaps.@futurepro62 on GitHub · 2026-11-24 15:54 UTC · original · edited 2026-11-24 16:02 UTC
Full-suite run, since this PR has no test report yet. Tested exact head
6cb357b(on its base930e8b4).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.tls_dir_total_len_saturates_instead_of_overflowing,rva_to_offset_in_file_layout_rejects_offsets_past_eof.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
@DavidM1911 on GitHub · 2026-11-24 17:01 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.Thanks!
@b3IKK on GitHub · 2026-11-24 18:50 UTC · original
Thanks @pickles976 — pinned the exact boundary in \
1e920a0\ (aw_ptr + delta == data.len() - 1\ returns \Some,
aw_ptr + delta == data.len()\ returns \None) and re-ran \scripts/test.ps1\ and the 60 s \scripts/smoke.ps1\ run.
@DavidM1911 on GitHub · 2026-11-26 05:03 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.