Skip to content

Fix GH-11374, backport upstream pcre2 fix #12439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/pcre/pcre2lib/pcre2_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
60 changes: 60 additions & 0 deletions ext/pcre/tests/gh11374.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--TEST--
GH-11374 (PCRE regular expression without JIT enabled gives different result)
--FILE--
<?php

$regex = '
(?<types>
(?:
(?:\{ (?&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
)

)