From 06bc264cbc4a936b38b269e9124475e883aa9a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 14 Oct 2023 23:48:00 +0200 Subject: [PATCH] backport GH 300 pcre2 fix --- ext/pcre/pcre2lib/pcre2_match.c | 2 +- ext/pcre/tests/gh11374.phpt | 60 +++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 ext/pcre/tests/gh11374.phpt diff --git a/ext/pcre/pcre2lib/pcre2_match.c b/ext/pcre/pcre2lib/pcre2_match.c index f28cdbb47a515..e62659a556145 100644 --- a/ext/pcre/pcre2lib/pcre2_match.c +++ b/ext/pcre/pcre2lib/pcre2_match.c @@ -5640,7 +5640,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode); { P = (heapframe *)((char *)N - frame_size); memcpy((char *)F + offsetof(heapframe, ovector), P->ovector, - P->offset_top * sizeof(PCRE2_SIZE)); + Foffset_top * sizeof(PCRE2_SIZE)); Foffset_top = P->offset_top; Fcapture_last = P->capture_last; Fcurrent_recurse = P->current_recurse; diff --git a/ext/pcre/tests/gh11374.phpt b/ext/pcre/tests/gh11374.phpt new file mode 100644 index 0000000000000..07f8f4bccfd0a --- /dev/null +++ b/ext/pcre/tests/gh11374.phpt @@ -0,0 +1,60 @@ +--TEST-- +GH-11374 (PCRE regular expression without JIT enabled gives different result) +--FILE-- + + (?: + (?:\{ (?&types) \}) + | (a) + ) + (\*?) + ) +'; + +ini_set('pcre.jit', '0'); +$res = preg_match('{^' . $regex . '$}x', '{a}', $matches, PREG_OFFSET_CAPTURE); +ini_set('pcre.jit', '1'); +// regex must be different to prevent regex cache, so just add 2nd "x" modifier +$res2 = preg_match('{^' . $regex . '$}xx', '{a}', $matches2, PREG_OFFSET_CAPTURE); + +var_dump($matches === $matches2); +print_r($matches); + +?> +--EXPECT-- +bool(true) +Array +( + [0] => Array + ( + [0] => {a} + [1] => 0 + ) + + [types] => Array + ( + [0] => {a} + [1] => 0 + ) + + [1] => Array + ( + [0] => {a} + [1] => 0 + ) + + [2] => Array + ( + [0] => + [1] => -1 + ) + + [3] => Array + ( + [0] => + [1] => 3 + ) + +)