Skip to content

SWF(bug): return error for overflowing safetensors header shapes - #89

Merged
maplepaladin73 merged 3 commits into
mainfrom
devin/1795404529-safetensors-overflow
Nov 23, 2026
Merged

maplepaladin73 merged 3 commits into
mainfrom
devin/1795404529-safetensors-overflow

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Malformed safetensors headers no longer panic or wrap the pre-flight OOM estimate: shape products, per-tensor byte counts, and cumulative totals in estimate_load_bytes / estimate_has_fp8 now use checked arithmetic and return an error before real safetensors validation. The spark-runtime OOM comparisons also use saturating_add so a huge but representable estimate cannot wrap the reserve addition.

Root cause: the estimate path computed shape.iter().product(), numel * elem_bytes, and running totals with unchecked arithmetic. A header such as "shape":[u64::MAX,2] panicked in debug builds and could wrap to a small estimate in release builds before safetensors::SafeTensors rejected the checkpoint.

Test plan

Try it (CPU):

ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-runtime --lib weights::loader::tests::estimates_reject_overflowing_header_shapes -- --exact --nocapture
  • Before: with this regression test applied to main, the same command panicked with attempt to multiply with overflow and failed.
  • After: targeted test → 1 passed; full ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-runtime --lib → 585 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 both byte-estimate paths.
  • Untested: live model load / GPU validation (CPU-only header-estimate change).

Notes for reviewers

I kept the existing dtype fallback, shape-entry parsing, and CSF decoded_len(...).unwrap_or(0) behavior unchanged to keep this scoped to the confirmed overflow path and preserve indexed-load handling of unrouted malformed CSF tensors. Devin Review's test-file and CSF findings are addressed in follow-up commits on this branch.

CLA


Software Factory opened this PR for Robert
Implemented in session Return error for overflowing safetensors header shapes
Review with Devin · Open in Devin Desktop


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

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@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

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@maplepaladin73
maplepaladin73 merged commit f76ee89 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