From fd6e36310fd2c49eef1b77a9cf9741833204de4e Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Fri, 14 Aug 2026 17:47:26 +0200 Subject: [PATCH] revert gguf fix --- ggml/src/gguf.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/ggml/src/gguf.cpp b/ggml/src/gguf.cpp index b6ce8325a5..6c7b581781 100644 --- a/ggml/src/gguf.cpp +++ b/ggml/src/gguf.cpp @@ -689,17 +689,12 @@ static struct gguf_context * gguf_init_from_reader(const struct gguf_reader & gr } // check that the total number of elements is representable - bool ne_overflow = false; - int64_t ne_total = info.t.ne[0]; - for (uint32_t j = 1; ok && j < GGML_MAX_DIMS; ++j) { - if (info.t.ne[j] != 0 && ne_total != 0 && INT64_MAX/info.t.ne[j] <= ne_total) { - ne_overflow = true; - break; - } - ne_total *= info.t.ne[j]; - } + // (a zero-element tensor is trivially representable; the guard also avoids a division by zero below) + if (ok && ggml_nelements(&info.t) > 0 && + ((INT64_MAX/info.t.ne[1] <= info.t.ne[0]) || + (INT64_MAX/info.t.ne[2] <= info.t.ne[0]*info.t.ne[1]) || + (INT64_MAX/info.t.ne[3] <= info.t.ne[0]*info.t.ne[1]*info.t.ne[2]))) { - if (ok && ne_overflow) { GGML_LOG_ERROR("%s: total number of elements in tensor '%s' with shape " "(%" PRIi64 ", %" PRIi64 ", %" PRIi64 ", %" PRIi64 ") is >= %" PRIi64 "\n", __func__, info.t.name, info.t.ne[0], info.t.ne[1], info.t.ne[2], info.t.ne[3], INT64_MAX);