]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
ggml: handle ggml_init failure to fix NULL pointer deref (#8692)
authorDavidKorczynski <redacted>
Thu, 25 Jul 2024 21:23:05 +0000 (22:23 +0100)
committerGitHub <redacted>
Thu, 25 Jul 2024 21:23:05 +0000 (23:23 +0200)
`ggml_init` can fail if no unused context is found. In that case, a NULL-pointer deref will happen later in the code during a call to `ggml_set_on_alloc`.

This fixes it by bailing out if no context is found.

ggml/src/ggml.c

index f65837e856ac35f12fa91ded964f64de1ad0e462..29afcc7f8978bdc124975a2cd248d49bd6eb486b 100644 (file)
@@ -21096,6 +21096,12 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p
         };
 
         *params.ctx = ggml_init(pdata);
+        if (*params.ctx == NULL) {
+            fprintf(stderr, "%s: failed to initialize context\n", __func__);
+            fclose(file);
+            gguf_free(ctx);
+            return NULL;
+        }
 
         struct ggml_context * ctx_data = *params.ctx;