Skip to content

LLM inference in C/C++

C++ ggml

ggml: fix OOB write in ggml_acc with negative offset (#30135)

Jasmine-tim8ae386707bed
diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c
index 9bcabdbd34..882cdf4a5e 100644
--- a/ggml/src/ggml.c
+++ b/ggml/src/ggml.c
@@ -2199,6 +2199,7 @@ static struct ggml_tensor * ggml_acc_impl(
struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a);
+ GGML_ASSERT(offset < (size_t)(1 << 30));
int32_t params[] = { nb1, nb2, nb3, offset, inplace ? 1 : 0 };
ggml_set_op_params(result, params, sizeof(params));