]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
llama : sanitize tokens in the upper bound (#9359)
authorslaren <redacted>
Sun, 8 Sep 2024 10:41:51 +0000 (12:41 +0200)
committerGitHub <redacted>
Sun, 8 Sep 2024 10:41:51 +0000 (12:41 +0200)
src/llama.cpp

index f590bcd3b90476243c469009886060183f62f2cb..39e20440eea83889697eca5e612c0220c0e328a9 100644 (file)
@@ -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;
         }