Repository navigation
fix(cluster): refuse headers whose byte counts or offsets overflow - #488
Merged
Merged
Conversation
Owner
|
Thank you, @chaog992, for the malformed-header cases and the empty-tensor compatibility checks. The parser now rejects overflowing absolute offsets and byte counts while preserving zero-sized tensors and the last valid 64-bit boundary. Your regression passes, and your original commit landed on main. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
This is the follow-up left open in #460.
parseHeaderinzig/src/cluster/checkpoint.zig, the cluster's own safetensors reader, multiplied a tensor's dimensions and dtype size and added the header length to its start offset without overflow checks, so a malformed header panicked in Debug and was illegal behavior in the default ReleaseFast build. It also accepted an end offset whosestart + bytesoverflows 64 bits, leaving that overflow to whatever adds them later. For example, in ReleaseFast aU8tensor with shape[4611686018427387904, 4]anddata_offsets[0, 0]was accepted as empty, because its byte count wrapped to zero.An entry whose absolute end (8 + header length +
end) would overflow the 64-bit range is nowBadHeader, which also keeps every tensor'sstartandstart + byteswithin 64 bits. The byte count multiplies the dtype size by each dimension with saturating multiplication: a zero dimension anywhere still gives 0, and an overflow stops at 2^64 - 1, whichbytescan no longer reach, so it isInconsistentlike any other mismatch. The core reader from #460 multiplies withstd.math.mulinstead; here that would refuse BF16[16777216, 16777216, 32768, 0], which the cluster base accepts, because its element count, 2^63, fits in a u64, but times 2 bytes it reaches 2^64 before the trailing zero. A header the base parser accepts in Debug without integer overflow, with every tensor's absolute end within 64 bits, parses to the same tensors.Tensors are still not checked against their file's size, and the arithmetic that later uses them (the planner's sums of
bytes, the loader's column-split offsets) is unchecked; those would be separate changes.Receipt
041d14a9(1.0.1), fix02322c1b, Zig 0.17.0, Linux x86_64 under WSL2.test-cluster), so on Linux I ran its tests withzig test -lc -O Debug --dep lanes --dep fabric -Mroot=zig/src/cluster/cluster.zig -Mlanes=zig/src/core/lanes/lanes.zig -Mfabric=zig/src/fabric/fabric.zig, and again with-O ReleaseFast. Both give 81 tests: 73 passed, 6 skipped, 2 failed. The base gives 72 passed, 6 skipped and the same 2 failures,status's "the K3 status on four Studios…" andplan_test's "a node whose wired limit is too low…". The skips needTF_K3_DIR,TF_CLUSTER_PROBESorTF_CLUSTER_REPORT.TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bitatd9d758fb(763 tensors) parse identically before and after, in Debug and ReleaseFast: name, file, start, bytes, dtype, shape and role.python3 tools/zig/lean_check.pyfinds 513 problems on the base and the same 513 with this change; none are incluster/checkpoint.zig.zig fmt --check zig/src/cluster/checkpoint.zigflags only the dtype table at lines 11–12, as it does on the base; this change leaves the table alone. The cluster module compiles foraarch64-macoswith-mcpu apple_m1 --test-no-exec; this is a compile check, not a macOS test run.zig build test-clusterandtf-k3-cluster(Mac build graph), cluster runs and model loads. The change only touches header parsing, not inference arithmetic.