Skip to content

SWF(bug): return error for overflowing GGUF tensor directory math - #90

Merged
maplepaladin73 merged 2 commits into
mainfrom
devin/1795406317-gguf-overflow
Nov 23, 2026
Merged

maplepaladin73 merged 2 commits into
mainfrom
devin/1795406317-gguf-overflow

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Malformed GGUF tensor directory entries now return clean errors instead of panicking in debug builds or wrapping in release builds. Checked arithmetic now covers element counts, byte sizes, absolute offsets, BF16 pre-flight estimates, and the mmap slice bounds.

Root cause: TensorInfo::num_elements(), tensor_byte_size(), tensor_abs_offset(), est_bf16(), and load_pass() used unchecked arithmetic. A tensor offset of u64::MAX or dims such as [4294967296, 4294967296] could panic on attempt to multiply/add with overflow in debug, or wrap in release and produce a wrong offset / underestimated OOM footprint before mmap.get(start..start + raw_len).

Test plan

Try it (CPU):

ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-runtime --lib malformed_gguf -- --nocapture
  • Before: with the regression tests applied to main (5938b44), the debug run failed with attempt to multiply with overflow / attempt to add with overflow; the release run let malformed GGUFs load or fail later with an unrelated mock error instead of the overflow error.
  • After: targeted debug → 4 passed; release targeted → 4 passed; full ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-runtime --lib → 588 passed; 0 failed; 11 ignored.
  • cargo fmt --all -- --check
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --workspace --tests -- -Dwarnings
  • bash scripts/check-license-headers.sh (4283 files checked, 0 invalid)
  • typos
  • Added regression coverage for offset overflow, dim-product overflow in both estimate and load paths, and byte-size overflow.
  • Untested: live model load / GPU validation (CPU-only malformed-container change).

Notes for reviewers

The mmap read is now split into mmap.get(start..) then tail.get(..raw_len) so start + raw_len cannot wrap. The OOM pre-flight reserve addition uses saturating_add, and combined backbone/mmproj estimates use checked addition. The separate CLIP mmproj patch-frame index issue was left untouched.

CLA


Software Factory opened this PR for Robert
Implemented in session Return error for overflowing GGUF tensor directory math
Review with Devin · Open in Devin Desktop


maplepaladin73 and others added 2 commits November 23, 2026 04:00
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@maplepaladin73
maplepaladin73 merged commit 06efed1 into main Nov 23, 2026
1 check 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.

1 participant