DavidKorczynski commited on
Commit
dc51517
·
1 Parent(s): 94a6436

ggml: handle ggml_init failure to fix NULL pointer deref (llama/8692)

Browse files

`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.

Files changed (1) hide show
  1. ggml/src/ggml.c +6 -0
ggml/src/ggml.c CHANGED
@@ -21095,6 +21095,12 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p
21095
  };
21096
 
21097
  *params.ctx = ggml_init(pdata);
 
 
 
 
 
 
21098
 
21099
  struct ggml_context * ctx_data = *params.ctx;
21100
 
 
21095
  };
21096
 
21097
  *params.ctx = ggml_init(pdata);
21098
+ if (*params.ctx == NULL) {
21099
+ fprintf(stderr, "%s: failed to initialize context\n", __func__);
21100
+ fclose(file);
21101
+ gguf_free(ctx);
21102
+ return NULL;
21103
+ }
21104
 
21105
  struct ggml_context * ctx_data = *params.ctx;
21106