gguf : fix ctx size for no_alloc == true

This commit is contained in:
Georgi Gerganov
2026-02-22 15:54:44 +02:00
parent 4e89ec67fa
commit 09788740f3
+12 -1
View File
@@ -704,7 +704,17 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
// compute the exact size needed for the new ggml_context
size_t mem_size = 0;
{
if (params.no_alloc) {
if (n_tensors != 0 && SIZE_MAX / n_tensors < ggml_tensor_overhead()) {
GGML_LOG_ERROR("%s: memory size overflow while allocating ggml context\n", __func__);
gguf_free(ctx);
return nullptr;
}
const size_t overhead = n_tensors * ggml_tensor_overhead();
mem_size = overhead;
} else {
if ((n_tensors + 1) != 0 && SIZE_MAX / (n_tensors + 1) < ggml_tensor_overhead()) {
GGML_LOG_ERROR("%s: memory size overflow while allocating ggml context\n", __func__);
gguf_free(ctx);
@@ -712,6 +722,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
}
const size_t overhead = (n_tensors + 1) * ggml_tensor_overhead();
if (SIZE_MAX - overhead < ctx->size) {
GGML_LOG_ERROR("%s: memory size overflow while allocating ggml context\n", __func__);
gguf_free(ctx);