From: matiaslin Date: Sun, 29 Sep 2024 12:25:00 +0000 (-0700) Subject: common : ensure llama_batch size does not exceed max size (#9668) X-Git-Tag: upstream/0.0.4488~646 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=faac0bae265449fd988c57bf894018edc36fbe1e;p=pkg%2Fggml%2Fsources%2Fllama.cpp common : ensure llama_batch size does not exceed max size (#9668) A crash was observed when the number of tokens added to a batch exceeds llama_batch size. An assertion in llama_batch_add was added to protect against llama_batch size overflow. --- diff --git a/common/common.cpp b/common/common.cpp index e2b8574b..a0611f3d 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1437,6 +1437,8 @@ void llama_batch_add( llama_pos pos, const std::vector & seq_ids, bool logits) { + GGML_ASSERT(batch.seq_id[batch.n_tokens] && "llama_batch size exceeded"); + batch.token [batch.n_tokens] = id; batch.pos [batch.n_tokens] = pos; batch.n_seq_id[batch.n_tokens] = seq_ids.size();