Skip to content

Commit

Permalink
llama : sanitize tokens in the upper bound (#9359)
Browse files Browse the repository at this point in the history
  • Loading branch information
slaren authored Sep 8, 2024
1 parent 00b02bb commit eae5971
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit eae5971

Please sign in to comment.