Skip to content

Commit 49ce0ab

Browse files
ggml: handle ggml_init failure to fix NULL pointer deref (#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.
1 parent 4226a8d commit 49ce0ab

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ggml/src/ggml.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21096,6 +21096,12 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p
2109621096
};
2109721097

2109821098
*params.ctx = ggml_init(pdata);
21099+
if (*params.ctx == NULL) {
21100+
fprintf(stderr, "%s: failed to initialize context\n", __func__);
21101+
fclose(file);
21102+
gguf_free(ctx);
21103+
return NULL;
21104+
}
2109921105

2110021106
struct ggml_context * ctx_data = *params.ctx;
2110121107

0 commit comments

Comments
 (0)