Skip to content

Commit 538f609

Browse files
committed
ggml : fix possible underflow in ggml_nbytes
1 parent 6c8d01a commit 538f609

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ggml/src/ggml.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,12 @@ int64_t ggml_nrows(const struct ggml_tensor * tensor) {
11511151
}
11521152

11531153
size_t ggml_nbytes(const struct ggml_tensor * tensor) {
1154+
for (int i = 0; i < GGML_MAX_DIMS; ++i) {
1155+
if (tensor->ne[i] <= 0) {
1156+
return 0;
1157+
}
1158+
}
1159+
11541160
size_t nbytes;
11551161
const size_t blck_size = ggml_blck_size(tensor->type);
11561162
if (blck_size == 1) {

0 commit comments

Comments
 (0)