From: slaren Date: Sun, 8 Sep 2024 10:41:51 +0000 (+0200) Subject: llama : sanitize tokens in the upper bound (#9359) X-Git-Tag: upstream/0.0.4488~786 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=eae597182cb61bbde0b26e7cec5999d28b9327fe;p=pkg%2Fggml%2Fsources%2Fllama.cpp llama : sanitize tokens in the upper bound (#9359) --- diff --git a/src/llama.cpp b/src/llama.cpp index f590bcd3..39e20440 100644 --- a/src/llama.cpp +++ b/src/llama.cpp @@ -16077,7 +16077,7 @@ static int llama_decode_internal( } for (uint32_t i = 0; i < n_tokens_all; ++i) { - if (batch_all.token[i] < 0) { + if (batch_all.token[i] < 0 || (uint32_t)batch_all.token[i] >= lctx.model.vocab.n_vocab) { LLAMA_LOG_ERROR("%s: invalid token[%d] = %d", __func__, i, batch_all.token[i]); return -1; } @@ -16376,7 +16376,7 @@ static int llama_encode_internal( } for (uint32_t i = 0; i < n_tokens; ++i) { - if (batch.token[i] < 0) { + if (batch.token[i] < 0 || (uint32_t)batch.token[i] >= lctx.model.vocab.n_vocab) { LLAMA_LOG_ERROR("%s: invalid token[%d] = %d", __func__, i, batch.token[i]); return -1; }