From: Georgi Gerganov Date: Fri, 17 Nov 2023 08:12:58 +0000 (+0200) Subject: gguf : prevent out-of-bounds-access on invalid magic (close #614) X-Git-Tag: upstream/0.0.1642~1193 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=4af8f4a4a7fde79f0b86b59cbe5faadd92de2aec;p=pkg%2Fggml%2Fsources%2Fggml gguf : prevent out-of-bounds-access on invalid magic (close #614) --- diff --git a/src/ggml.c b/src/ggml.c index ada1067d..f577ac8b 100644 --- a/src/ggml.c +++ b/src/ggml.c @@ -17941,6 +17941,7 @@ struct gguf_kv { struct gguf_header { char magic[4]; + uint32_t version; uint64_t n_tensors; // GGUFv2 uint64_t n_kv; // GGUFv2 @@ -18030,7 +18031,7 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p for (uint32_t i = 0; i < sizeof(magic); i++) { if (magic[i] != GGUF_MAGIC[i]) { - fprintf(stderr, "%s: invalid magic characters %s.\n", __func__, magic); + fprintf(stderr, "%s: invalid magic characters '%c%c%c%c'\n", __func__, magic[0], magic[1], magic[2], magic[3]); fclose(file); return NULL; } @@ -18045,7 +18046,6 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p { strncpy(ctx->header.magic, magic, 4); - ctx->kv = NULL; ctx->infos = NULL; ctx->data = NULL;