Skip to content

fix: reject tensor shapes that overflow uint64 - #72

Merged
thxCode merged 1 commit into
gpustack:mainfrom
jpatel2005:fix/tensor-size-overflow
Nov 19, 2026
Merged

thxCode merged 1 commit into
gpustack:mainfrom
jpatel2005:fix/tensor-size-overflow

Conversation

@jpatel2005

@jpatel2005 jpatel2005 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

GGUFTensorInfo.Elements and Bytes panic on uint64 overflow, as intended since #20, but the tensor info reader accepts any shape, so nothing stops a file from reaching those panics. A tensor such as F32 (2^62, 1) makes ParseGGUFFile panic:

panic: gguf: uint64 overflow in Bytes nb[1]: 4 * 4611686018427387904

Split sets skip the data size check and panic later in EstimateLLaMACppRun.

The reader now refuses a tensor when the product of its dimensions, or that product times the type size, overflows uint64. The first check is the product Elements() computes, and every intermediate value in Bytes() is bounded by the second, so accepted tensors cannot overflow in Elements() or Bytes(). Both methods are unchanged.

For block-quantized types, this bound is conservative because it does not account for the block size. It can reject some extreme shapes whose quantized byte size would otherwise fit in uint64.

TestTensorInfoReaderRejectsOverflowingShapes covers one shape that overflows the element count and one that overflows Bytes(); both fail without the fix.

Types with a zero block size (Q4_2, Q4_3) are refused separately in #71.

Signed-off-by: Jai Patel <mitjaipp@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 15, 2026 07:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@gpustack-code-review

gpustack-code-review Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 2 issue(s) in this PR.

  • ✅ Successfully posted inline: 2 comment(s)

Comment thread file.go Resolved
Comment thread file.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the tensor-shape overflow protection changes.

No open issues 🎉

Review effort: Balanced

@thxCode thxCode left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thxCode
thxCode merged commit fbd0828 into gpustack:main Nov 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants