Skip to content

Commit 3cfbbdb

Browse files
Merge commit from fork
* vocab : prevent integer overflow during load * Add static cast and GGML_ABORT --------- Co-authored-by: Georgi Gerganov <[email protected]>
1 parent 80709b7 commit 3cfbbdb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/llama-vocab.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <set>
2020
#include <unordered_map>
2121
#include <cctype>
22+
#include <cinttypes>
2223

2324
//
2425
// helpers
@@ -2572,6 +2573,10 @@ int32_t llama_vocab::impl::token_to_piece(llama_token token, char * buf, int32_t
25722573
// copy piece chars to output text buffer
25732574
// skip up to 'lstrip' leading spaces before copying
25742575
auto _try_copy = [=] (const char * token, size_t size) -> int32_t {
2576+
if (size >= static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
2577+
GGML_ABORT("invalid token size: %zu exceeds int32_t limit", size);
2578+
}
2579+
25752580
for (int32_t i = 0; i < lstrip && size && *token == ' '; ++i) {
25762581
token++;
25772582
size--;

0 commit comments

Comments
 (0)