From 2eda6161d67d80a6ee9f2d2d018b893637928a2c Mon Sep 17 00:00:00 2001 From: Phil Turnbull Date: Tue, 7 Aug 2018 12:24:25 -0400 Subject: [PATCH] Avoid integer truncation when serializing tag lengths A tag longer than 255 characters will be incorrectly serialized. Co-authored-by: Rahul Zhade --- src/scanner.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scanner.cc b/src/scanner.cc index 31feb38..0077c98 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -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(tag.type); buffer[i++] = name_length;