Skip to content

Commit faa1904

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-15652: Segmentation fault in the Zend engine when JIT enabled (#15717)
2 parents db9a7aa + be85896 commit faa1904

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,16 +623,16 @@ static zend_property_info* zend_get_known_property_info(const zend_op_array *op_
623623
return NULL;
624624
}
625625

626-
static bool zend_may_be_dynamic_property(zend_class_entry *ce, zend_string *member, bool on_this, zend_string *filename)
626+
static bool zend_may_be_dynamic_property(zend_class_entry *ce, zend_string *member, bool on_this, const zend_op_array *op_array)
627627
{
628628
zend_property_info *info;
629629

630-
if (!ce || (ce->ce_flags & ZEND_ACC_TRAIT)) {
630+
if (!ce || (ce->ce_flags & ZEND_ACC_TRAIT) || (op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
631631
return 1;
632632
}
633633

634634
if (!(ce->ce_flags & ZEND_ACC_IMMUTABLE)) {
635-
if (ce->info.user.filename != filename) {
635+
if (ce->info.user.filename != op_array->filename) {
636636
/* class declaration might be changed independently */
637637
return 1;
638638
}

ext/opcache/jit/zend_jit_ir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13888,7 +13888,7 @@ static int zend_jit_fetch_obj(zend_jit_ctx *jit,
1388813888
ir_ref offset_ref = ir_LOAD_A(
1388913889
ir_ADD_OFFSET(run_time_cache, (opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*)));
1389013890

13891-
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array->filename);
13891+
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array);
1389213892
if (may_be_dynamic) {
1389313893
ir_ref if_dynamic = ir_IF(ir_LT(offset_ref, ir_CONST_ADDR(ZEND_FIRST_PROPERTY_OFFSET)));
1389413894
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)