From: Sigbjørn Skjæret Date: Tue, 4 Aug 2026 08:40:02 +0000 (+0200) Subject: vocab : validate plamo2 byte tokens (#26511) X-Git-Tag: upstream/0.0.10438~177 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=cf06ad7dfe79e7bf2934150d4fefe1ce8db05490;p=pkg%2Fggml%2Fsources%2Fllama.cpp vocab : validate plamo2 byte tokens (#26511) * validate plamo2 byte tokens * --typo --- diff --git a/src/llama-vocab.cpp b/src/llama-vocab.cpp index 10032a8c6..4a01dfd4c 100644 --- a/src/llama-vocab.cpp +++ b/src/llama-vocab.cpp @@ -1373,8 +1373,10 @@ struct llm_tokenizer_plamo2 : llm_tokenizer { if (vocab.is_byte(token_id)) { if (entry.text.length() == 6 && entry.text.substr(0, 3) == "<0x" && entry.text.back() == '>') { std::string hex_str = entry.text.substr(3, 2); - int byte_val = std::stoi(hex_str, nullptr, 16); - bytes_[byte_val] = static_cast(token_id); + if (std::isxdigit(static_cast(hex_str[0])) && std::isxdigit(static_cast(hex_str[1]))) { + int byte_val = std::stoi(hex_str, nullptr, 16); + bytes_[byte_val] = static_cast(token_id); + } } continue; } @@ -3625,12 +3627,15 @@ int32_t llama_vocab::impl::token_to_piece(llama_token token, char * buf, int32_t if (vocab.is_byte(token)) { // Handle byte tokens like <0xXX> if (token_text.length() == 6 && token_text.substr(0, 3) == "<0x" && token_text.back() == '>') { - int hex_val = std::stoi(token_text.substr(3, 2), nullptr, 16); - if (length < 1) { - return -1; + std::string hex_str = token_text.substr(3, 2); + if (std::isxdigit(static_cast(hex_str[0])) && std::isxdigit(static_cast(hex_str[1]))) { + int hex_val = std::stoi(hex_str, nullptr, 16); + if (length < 1) { + return -1; + } + buf[0] = static_cast(hex_val); + return 1; } - buf[0] = static_cast(hex_val); - return 1; } }