Skip to content

torch pth: reject tensor shapes whose element count overflows - #4322

Merged
ashhart merged 3 commits into
mainfrom
lead/torch-pth-overflow
Nov 21, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/torch-pth-overflow

Conversation

@ashhart

@ashhart ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Torch .pth checkpoints: a tensor shape whose element count overflows u64 now returns BadArchive instead of panicking (Debug) or wrapping (release).

Both readers, readRaw and readF32, now multiply the dimensions with checked u64 arithmetic. A count of exactly 2^64 - 1 is still representable; 2^64 and above is refused. Zero dimensions and every valid shape keep their existing arithmetic and stride checks, and the storage-size multiplication was already checked.

Test: zig build test-torch-pth-overflow-host reads a contiguous [2^32, 2^32] tensor through both readers. On main it panics with integer overflow; here both return the archive error.

  • Synthena

@ashhart
ashhart force-pushed the lead/torch-pth-overflow branch from 4e42a01 to d436d60 Compare November 21, 2026 19:01
@ashhart
ashhart merged commit 916dff9 into main Nov 21, 2026
2 of 12 checks passed
@ashhart
ashhart deleted the lead/torch-pth-overflow branch November 21, 2026 19:01
ashhart added a commit that referenced this pull request Nov 22, 2026
Unreleased: the five (#N) placeholders get their PR numbers, the two (#PR)
duplicates go, #3192's line goes (#4427 replaced that behaviour on main and
its line refs #3192), #3960 is named as the PR that landed #2799, and the
penalty under --instruct-sampling card; ?token= Web addresses and pull's
digest and size checks).

Sixteen PRs merged 20-21 Nov with no line anywhere: a blank lines file
replaced each PR's own line at landing. #4321 and #4322 go under
Unreleased, the twelve that shipped in 1.3.3 under 1.3.3, and the two
1.3.1 lines that carried no PR number get #3941 and #4022.

docs/environment.md: Flash Next checks 37 settings, and TF_GLM_INDEX_SPLIT
(registered by #4510) gets its row.
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