From 2b926df83600f952a0d74ddcbcad1c840831fd76 Mon Sep 17 00:00:00 2001 From: Zoltan Herczeg Date: Wed, 15 Nov 2023 07:46:34 +0000 Subject: [PATCH] Fix early fail detection --- src/pcre2_jit_compile.c | 12 +++++++----- src/pcre2_jit_test.c | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c index 6ec049d36..1da782224 100644 --- a/src/pcre2_jit_compile.c +++ b/src/pcre2_jit_compile.c @@ -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); @@ -1530,7 +1532,7 @@ do if (count < EARLY_FAIL_ENHANCE_MAX) { - cc = end + (1 + LINK_SIZE); + cc = end; continue; } break; diff --git a/src/pcre2_jit_test.c b/src/pcre2_jit_test.c index a518b865a..966869a09 100644 --- a/src/pcre2_jit_test.c +++ b/src/pcre2_jit_test.c @@ -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" },