Skip to content

Commit

Permalink
Merge pull request #463 from VeriFIT/foldcase_bug
Browse files Browse the repository at this point in the history
Subtraction of `ascii_shift_value` caused overflow. #patch
  • Loading branch information
Adda0 authored Nov 16, 2024
2 parents 3c05423 + 0d3b26e commit 2dc8437
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/re2parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace {
symbols.push_back(symbol);
// Foldcase causes RE2 to do a case-insensitive match, so transitions will be made for
// both uppercase and lowercase symbols
if (inst->foldcase()) {
if (inst->foldcase() && symbol >= 'a' && symbol <= 'z') {
symbols.push_back(symbol-ascii_shift_value);
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/re2parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,24 @@ TEST_CASE("mata::Parser error")
CHECK(!x.is_in_lang(Run{ Word{ 'a', 'a', 'a', 'a', 'a', 'a' }, {} }));
}

SECTION("Regex from issue #456") {
Nfa x;
mata::parser::create_nfa(&x, "[\\x00-\\x5a\\x5c-\\x7F]");

Nfa y;
State initial_s = 0;
State final_s = 1;
y.initial.insert(initial_s);
y.final.insert(final_s);
for (Symbol c = 0; c <= 0x7F; c++) {
if (c == 0x5B) {
continue;
}
y.delta.add(initial_s, c, final_s);
}
CHECK(are_equivalent(x, y));
}

SECTION("Another failing regex") {
Nfa x;
mata::parser::create_nfa(&x, "(cd(abcde)+)|(a(aaa)+|ccc+)");
Expand Down

0 comments on commit 2dc8437

Please sign in to comment.