Fix division by zero vulnerability in gguf_init_from_file_impl
This commit is contained in:
parent
cef1d23c5a
commit
646e4d0c85
|
|
@ -545,7 +545,14 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check for zero dimensions
|
||||
if (ok && (info.t.ne[1] == 0 || info.t.ne[2] == 0 || info.t.ne[3] == 0)) {
|
||||
GGML_LOG_ERROR("%s: tensor '%s' has zero dimension in shape "
|
||||
"(%" PRIi64 ", %" PRIi64 ", %" PRIi64 ", %" PRIi64 ")\n",
|
||||
__func__, info.t.name, info.t.ne[0], info.t.ne[1], info.t.ne[2], info.t.ne[3]);
|
||||
ok = false;
|
||||
}
|
||||
// check that the total number of elements is representable
|
||||
if (ok && ((INT64_MAX/info.t.ne[1] <= info.t.ne[0]) ||
|
||||
(INT64_MAX/info.t.ne[2] <= info.t.ne[0]*info.t.ne[1]) ||
|
||||
|
|
|
|||
Loading…
Reference in New Issue