From 2fbeb86db78d337fddce89e0f59bc54c1742b917 Mon Sep 17 00:00:00 2001 From: hhy569 <2932088330@qq.com> Date: Thu, 25 Jun 2026 17:09:33 +0800 Subject: [PATCH] Validate alignment value in gguf.cpp Add check for maximum alignment value in gguf.cpp --- ggml/src/gguf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ggml/src/gguf.cpp b/ggml/src/gguf.cpp index 5e1986182515..6d5dccee8512 100644 --- a/ggml/src/gguf.cpp +++ b/ggml/src/gguf.cpp @@ -609,7 +609,7 @@ static struct gguf_context * gguf_init_from_reader(const struct gguf_reader & gr const int alignment_idx = gguf_find_key(ctx, GGUF_KEY_GENERAL_ALIGNMENT); ctx->alignment = alignment_idx == -1 ? GGUF_DEFAULT_ALIGNMENT : gguf_get_val_u32(ctx, alignment_idx); - if (ctx->alignment == 0 || (ctx->alignment & (ctx->alignment - 1)) != 0) { + if (ctx->alignment == 0 || (ctx->alignment & (ctx->alignment - 1)) != 0 || ctx->alignment > 1048576) { GGML_LOG_ERROR("%s: alignment %zu is not a power of 2\n", __func__, ctx->alignment); gguf_free(ctx); return nullptr;