From: DavidKorczynski Date: Thu, 25 Jul 2024 21:23:05 +0000 (+0100) Subject: ggml: handle ggml_init failure to fix NULL pointer deref (llama/8692) X-Git-Tag: upstream/1.7.4~534 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=0620fe00ec24d861a056a5353da1bb1959d63fdf;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp ggml: handle ggml_init failure to fix NULL pointer deref (llama/8692) `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. --- diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index c6117c37..43198666 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -21095,6 +21095,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;