LibRegex: Bail parsing class set characters upon early EOF

Otherwise, we reach a skip() invocation at the end of this function,
which crashes due to EOF. Caught by test262.
This commit is contained in:
Timothy Flynn 2023-06-23 11:02:11 -04:00 committed by Andreas Kling
parent 32502fceed
commit 8b668da9d5
Notes: sideshowbarker 2024-07-16 23:57:20 +09:00
2 changed files with 22 additions and 0 deletions

View File

@ -779,6 +779,23 @@ TEST_CASE(ECMA262_unicode_match)
}
}
TEST_CASE(ECMA262_unicode_sets_parser_error)
{
struct _test {
StringView pattern;
regex::Error error;
};
constexpr _test tests[] {
{ "[[]"sv, regex::Error::InvalidPattern },
};
for (auto test : tests) {
Regex<ECMA262> re(test.pattern, (ECMAScriptFlags)regex::AllFlags::UnicodeSets);
EXPECT_EQ(re.parser_result.error, test.error);
}
}
TEST_CASE(ECMA262_unicode_sets_match)
{
struct _test {

View File

@ -2224,6 +2224,11 @@ Optional<u32> ECMA262Parser::parse_class_set_character()
"&&"sv, "!!"sv, "##"sv, "$$"sv, "%%"sv, "**"sv, "++"sv, ",,"sv, ".."sv, "::"sv, ";;"sv, "<<"sv, "=="sv, ">>"sv, "??"sv, "@@"sv, "^^"sv, "``"sv, "~~"sv
};
if (done()) {
set_error(Error::InvalidPattern);
return {};
}
auto start_position = tell();
ArmedScopeGuard restore { [&] { back(tell() - start_position + 1); } };