Skip to content

Commit 274dbe2

Browse files
committed
Fix GH-24388: Tracing JIT segfault when a trace runs out of side exits
1 parent d4de18c commit 274dbe2

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ PHP NEWS
7070
SCCP is disabled). (Lazizbek Ergashev)
7171
. Fixed bug GH-24337 (JIT: segfault when decrementing a non-numeric string
7272
property). (Lazizbek Ergashev)
73+
. Fixed bug GH-24388 (Tracing JIT: segfault when a trace runs out of side
74+
exits). (Lazizbek Ergashev)
7375

7476
- PDO:
7577
. Fixed a duplicate warning when ATTR_STATEMENT_CLASS is rejected on a

‎ext/opcache/jit/zend_jit_ir.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4921,6 +4921,9 @@ static int zend_jit_inc_dec(zend_jit_ctx *jit, const zend_op *opline, uint32_t o
49214921

49224922
exit_point = zend_jit_trace_get_exit_point(opline + 1, 0);
49234923
exit_addr = zend_jit_trace_get_exit_addr(exit_point);
4924+
if (!exit_addr) {
4925+
return 0;
4926+
}
49244927
ir_GUARD_NOT(ir_OVERFLOW(ref), ir_CONST_ADDR(exit_addr));
49254928

49264929
if ((opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_PRE_DEC) &&
@@ -4962,6 +4965,9 @@ static int zend_jit_inc_dec(zend_jit_ctx *jit, const zend_op *opline, uint32_t o
49624965

49634966
exit_point = zend_jit_trace_get_exit_point(opline + 1, 0);
49644967
exit_addr = zend_jit_trace_get_exit_addr(exit_point);
4968+
if (!exit_addr) {
4969+
return 0;
4970+
}
49654971
ir_GUARD(ir_OVERFLOW(ref), ir_CONST_ADDR(exit_addr));
49664972

49674973
if (opline->result_type != IS_UNUSED) {

‎ext/opcache/tests/jit/gh24388.phpt‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
GH-24388 (Tracing JIT: segfault when a trace runs out of side exits)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=64M
8+
opcache.jit=tracing
9+
--EXTENSIONS--
10+
opcache
11+
--FILE--
12+
<?php
13+
$file = __DIR__ . "/gh24388.inc";
14+
15+
$code = '<?php function f(int $k, int $a) { switch ($k) {';
16+
for ($i = 0; $i < 507; $i++) {
17+
$code .= "case $i: \$l = $i; break;";
18+
}
19+
$code .= '} return ++$a; }';
20+
$code .= 'for ($i = 0; $i < 200; $i++) { $a = 3; f(0, $a); }';
21+
file_put_contents($file, $code);
22+
23+
include $file;
24+
?>
25+
DONE
26+
--CLEAN--
27+
<?php
28+
@unlink(__DIR__ . "/gh24388.inc");
29+
?>
30+
--EXPECT--
31+
DONE

0 commit comments

Comments
 (0)