Skip to content

Commit

Permalink
Fix early fail detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltan Herczeg committed Nov 15, 2023
1 parent b719b47 commit 2b926df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/pcre2_jit_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,15 +1512,17 @@ do
case OP_ONCE:
case OP_BRA:
case OP_CBRA:
end = cc + GET(cc, 1);

prev_fast_forward_allowed = fast_forward_allowed;
fast_forward_allowed = FALSE;

if (depth >= 4)
break;

end = bracketend(cc) - (1 + LINK_SIZE);
if (*end != OP_KET || (*cc == OP_CBRA && common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0))
if (count == 0 && cc[GET(cc, 1)] == OP_ALT)
count = 1;

end = bracketend(cc);
if (end[-1 - LINK_SIZE] != OP_KET || (*cc == OP_CBRA && common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0))
break;

count = detect_early_fail(common, cc, private_data_start, depth + 1, count, prev_fast_forward_allowed);
Expand All @@ -1530,7 +1532,7 @@ do

if (count < EARLY_FAIL_ENHANCE_MAX)
{
cc = end + (1 + LINK_SIZE);
cc = end;
continue;
}
break;
Expand Down
1 change: 1 addition & 0 deletions src/pcre2_jit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ static struct regression_test_case regression_test_cases[] = {
{ CM, A, 0, 0, "ab|cd", "CD" },
{ CM, A, 0, 0, "a1277|a1377|bX487", "bx487" },
{ CM, A, 0, 0, "a1277|a1377|bx487", "bX487" },
{ 0, A, 0, 0, "(a|)b*+a", "a" },

/* Greedy and non-greedy ? operators. */
{ MU, A, 0, 0, "(?:a)?a", "laab" },
Expand Down

0 comments on commit 2b926df

Please sign in to comment.