Skip to content

Commit 15bbae7

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix GH-11956: PCRE regular expressions with JIT enabled gives different result
2 parents c39d448 + d61efdf commit 15bbae7

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ PHP NEWS
1313
. Fixed bug GH-12186 (segfault copying/cloning a finalized HashContext).
1414
(MaxSem)
1515

16+
- PCRE:
17+
. Fixed bug GH-11956 (Backport upstream fix, PCRE regular expressions with
18+
JIT enabled gives different result). (nielsdos)
19+
1620
- SimpleXML:
1721
. Fixed bug GH-12170 (Can't use xpath with comments in SimpleXML). (nielsdos)
1822
. Fixed bug GH-12192 (SimpleXML infinite loop when getName() is called

ext/pcre/pcre2lib/pcre2_jit_compile.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11517,19 +11517,19 @@ if (exact > 1)
1151711517
}
1151811518
}
1151911519
else if (exact == 1)
11520-
{
1152111520
compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks, TRUE);
1152211521

11523-
if (early_fail_type == type_fail_range)
11524-
{
11525-
OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr);
11526-
OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + (int)sizeof(sljit_sw));
11527-
OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, TMP2, 0);
11528-
OP2(SLJIT_SUB, TMP2, 0, STR_PTR, 0, TMP2, 0);
11529-
add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_LESS_EQUAL, TMP2, 0, TMP1, 0));
11522+
if (early_fail_type == type_fail_range)
11523+
{
11524+
/* Range end first, followed by range start. */
11525+
OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr);
11526+
OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + (int)sizeof(sljit_sw));
11527+
OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, TMP2, 0);
11528+
OP2(SLJIT_SUB, TMP2, 0, STR_PTR, 0, TMP2, 0);
11529+
add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_LESS_EQUAL, TMP2, 0, TMP1, 0));
1153011530

11531-
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + (int)sizeof(sljit_sw), STR_PTR, 0);
11532-
}
11531+
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_PTR, 0);
11532+
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + (int)sizeof(sljit_sw), STR_PTR, 0);
1153311533
}
1153411534

1153511535
switch(opcode)

ext/pcre/tests/gh11956.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-11956 (PCRE regular expressions with JIT enabled gives different result)
3+
--INI--
4+
pcre.jit=1
5+
--FILE--
6+
<?php
7+
preg_match( '/<(\w+)[\s\w\-]+ id="S44_i89ew">/', '<br><div id="S44_i89ew">', $matches );
8+
var_dump($matches);
9+
?>
10+
--EXPECT--
11+
array(2) {
12+
[0]=>
13+
string(20) "<div id="S44_i89ew">"
14+
[1]=>
15+
string(2) "di"
16+
}

0 commit comments

Comments
 (0)