Added a sanity check for input size.

This commit is contained in:
Mike Lischke 2021-03-10 11:49:22 +01:00
parent 84d4ce73de
commit 5731e64e22
1 changed files with 2 additions and 2 deletions

View File

@ -45,8 +45,8 @@ void ANTLRInputStream::load(const std::string &input) {
void ANTLRInputStream::load(const char *data, size_t length) { void ANTLRInputStream::load(const char *data, size_t length) {
// Remove the UTF-8 BOM if present. // Remove the UTF-8 BOM if present.
const char bom[4] = "\xef\xbb\xbf"; const char *bom = "\xef\xbb\xbf";
if (strncmp(data, bom, 3) == 0) if (length > 3 && strncmp(data, bom, 3) == 0)
_data = antlrcpp::utf8_to_utf32(data + 3, data + length); _data = antlrcpp::utf8_to_utf32(data + 3, data + length);
else else
_data = antlrcpp::utf8_to_utf32(data, data + length); _data = antlrcpp::utf8_to_utf32(data, data + length);