diff --git a/file.go b/file.go index aa8707d..e354122 100644 --- a/file.go +++ b/file.go @@ -441,13 +441,8 @@ func parseGGUFFile(fs []_GGUFFileReadSeeker, o _GGUFReadOptions) (_ *GGUFFile, e // tensor infos if gf.TensorInfos == nil { - tc, ok := gf.Header.MetadataKV.Get("split.tensors.count") - if ok { - gf.TensorInfos = make(GGUFTensorInfos, 0, anyx.Number[int](tc.Value)) - } else { - // avoid preallocating with tensorCount (could be huge); start empty and append - gf.TensorInfos = make(GGUFTensorInfos, 0) - } + // avoid preallocating with tensorCount (could be huge); start empty and append + gf.TensorInfos = make(GGUFTensorInfos, 0) } { rd := _GGUFTensorInfoReader{_GGUFReader: rd} diff --git a/file_test.go b/file_test.go index 94d84ee..e271601 100644 --- a/file_test.go +++ b/file_test.go @@ -646,6 +646,13 @@ func TestParseGGUFArrayLengthDoS(t *testing.T) { } } +func TestParseGGUFFile_InvalidSplitTensorsCount(t *testing.T) { + kv := GGUFMetadataKV{Key: "split.tensors.count", ValueType: GGUFMetadataValueTypeString, Value: "-1"} + if _, err := ParseGGUFFile(writeProjectorGGUF(t, []GGUFMetadataKV{kv})); err != nil { + t.Errorf("unexpected error: %v", err) + } +} + // writeProjectorGGUF writes a projector file with no tensors and the given // vision metadata, in the order llama.cpp's loader reads it. func writeProjectorGGUF(t *testing.T, kvs []GGUFMetadataKV) string {