Avoid integer truncation when serializing tag lengths

A tag longer than 255 characters will be incorrectly serialized.

Co-authored-by: Rahul Zhade <zhade3@github.com>
This commit is contained in:
Phil Turnbull 2018-08-07 12:24:25 -04:00
parent 3e586b10fc
commit 2eda6161d6
No known key found for this signature in database
GPG Key ID: D81B30C00789D262
1 changed files with 1 additions and 0 deletions

View File

@ -34,6 +34,7 @@ struct Scanner {
Tag &tag = tags[j];
if (tag.type == CUSTOM) {
unsigned name_length = tag.custom_tag_name.size();
if (name_length > UINT8_MAX) break;
if (i + 2 + name_length >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) break;
buffer[i++] = static_cast<char>(tag.type);
buffer[i++] = name_length;