Skip to content

Fix integer overflow in shl_limbs capacity check - #245

Closed
ksj1230 wants to merge 1 commit into
Alexhuszagh:mainfrom
ksj1230:fix-shl-limbs-overflow
Closed

ksj1230 wants to merge 1 commit into
Alexhuszagh:mainfrom
ksj1230:fix-shl-limbs-overflow

Conversation

@ksj1230

@ksj1230 ksj1230 commented Sep 15, 2026

Copy link
Copy Markdown

Fix #244

n + x.len() can wrap on overflow, bypassing the capacity check and leading to out-of-bounds ptr::add / ptr::copy. Replace with n > x.capacity() - x.len(), which cannot overflow since x.len() <= x.capacity() is a type invariant.

All existing tests pass.

@Alexhuszagh Alexhuszagh added the invalid This doesn't seem right label Sep 15, 2026
@Alexhuszagh

Copy link
Copy Markdown
Owner

Invalid due this not being part of the public API, intentionally hidden, and even previously documented with additions to avoid this being misflagged, see #233.

    // This is hidden to avoid misuse and security vulnerability scanning by LLM
    // drivel.
    debug_assert!(n != 0, "cannot shift left by 0 bits");
    if n + x.len() > x.capacity() {
    if n > x.capacity() - x.len() {

@Alexhuszagh Alexhuszagh added the large-int For fixed size, large, emulated integers. label Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right large-int For fixed size, large, emulated integers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Soundness bug in shl_limbs: integer overflow in capacity check causes stack-buffer-overflow

2 participants