Skip to content

Commit 1e78cf9

Browse files
authored
Fix phpGH-15652: Segmentation fault in the Zend engine when JIT enabled (php#15717)
1 parent 57f9041 commit 1e78cf9

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,16 +669,16 @@ static zend_property_info* zend_get_known_property_info(const zend_op_array *op_
669669
return NULL;
670670
}
671671

672-
static bool zend_may_be_dynamic_property(zend_class_entry *ce, zend_string *member, bool on_this, zend_string *filename)
672+
static bool zend_may_be_dynamic_property(zend_class_entry *ce, zend_string *member, bool on_this, const zend_op_array *op_array)
673673
{
674674
zend_property_info *info;
675675

676-
if (!ce || (ce->ce_flags & ZEND_ACC_TRAIT)) {
676+
if (!ce || (ce->ce_flags & ZEND_ACC_TRAIT) || (op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
677677
return 1;
678678
}
679679

680680
if (!(ce->ce_flags & ZEND_ACC_IMMUTABLE)) {
681-
if (ce->info.user.filename != filename) {
681+
if (ce->info.user.filename != op_array->filename) {
682682
/* class declaration might be changed independently */
683683
return 1;
684684
}

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12200,7 +12200,7 @@ static int zend_jit_fetch_obj(dasm_State **Dst,
1220012200
| cmp REG2, TMP1
1220112201
| bne >5
1220212202
| MEM_ACCESS_64_WITH_UOFFSET ldr, REG0, REG0, ((opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*)), TMP1
12203-
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array->filename);
12203+
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array);
1220412204
if (may_be_dynamic) {
1220512205
| tst REG0, REG0
1220612206
if (opline->opcode == ZEND_FETCH_OBJ_W) {

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12964,7 +12964,7 @@ static int zend_jit_fetch_obj(dasm_State **Dst,
1296412964
| cmp r2, aword [FCARG1a + offsetof(zend_object, ce)]
1296512965
| jne >5
1296612966
| mov r0, aword [r0 + (opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*)]
12967-
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array->filename);
12967+
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array);
1296812968
if (may_be_dynamic) {
1296912969
| test r0, r0
1297012970
if (opline->opcode == ZEND_FETCH_OBJ_W) {

ext/opcache/tests/jit/gh15652.phpt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
JIT: FETCH_OBJ 007
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.jit_hot_func=2
9+
--FILE--
10+
<?php
11+
class C {}
12+
13+
trait T {
14+
public function equal(C $type): bool {
15+
return $type instanceof self && $this->value === $type->value;
16+
}
17+
}
18+
19+
class C1 extends C {
20+
use T;
21+
public function __construct(private int $value) {}
22+
}
23+
24+
class C2 extends C {
25+
use T;
26+
}
27+
28+
$x = new C1(1);
29+
var_dump($x->equal($x));
30+
var_dump($x->equal($x));
31+
$a = new C2("aaa");
32+
var_dump($a->equal($a));
33+
var_dump($a->equal($a));
34+
--EXPECTF--
35+
bool(true)
36+
bool(true)
37+
38+
Warning: Undefined property: C2::$value in %sgh15652.php on line 6
39+
40+
Warning: Undefined property: C2::$value in %sgh15652.php on line 6
41+
bool(true)
42+
43+
Warning: Undefined property: C2::$value in %sgh15652.php on line 6
44+
45+
Warning: Undefined property: C2::$value in %sgh15652.php on line 6
46+
bool(true)

0 commit comments

Comments
 (0)