ggml: ensure tensor size is valid (#14406)

When quantizing tensors during model creation validate that the resulting sizes match what is expected based on the shape.
This commit is contained in:
Bruce MacDonald
2026-02-24 21:52:44 -04:00
committed by GitHub
parent f4f0a4a471
commit 9d902d63ce
4 changed files with 96 additions and 10 deletions

View File

@@ -33,6 +33,9 @@ func (q quantizer) WriteTo(w io.Writer) (int64, error) {
slog.Warn("file read error", "tensor", q.from.Name, "file", q.Name(), "error", err)
return 0, fmt.Errorf("unable to read tensor %s from %s: %s", q.from.Name, q.Name(), err)
}
if uint64(len(data)) < q.from.Size() {
return 0, fmt.Errorf("tensor %s data size %d is less than expected %d from shape %v", q.from.Name, len(data), q.from.Size(), q.from.Shape)
}
var f32s []float32
newType := fsggml.TensorType(q.to.Kind)
if fsggml.TensorType(q.from.Kind) == fsggml.TensorTypeF32 {