Skip to content

Commit

Permalink
ggml: handle ggml_init failure to fix NULL pointer deref (#8692)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
DavidKorczynski authored Jul 25, 2024
1 parent 4226a8d commit 49ce0ab
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ggml/src/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 49ce0ab

Please sign in to comment.