Skip to content

Commit 8666977

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix missing readonly modification error with inc/dec in JIT
2 parents 4ea8699 + 7934a0f commit 8666977

9 files changed

+234
-0
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,13 @@ static ZEND_COLD zend_long _zend_jit_throw_dec_prop_error(zend_property_info *pr
26622662

26632663
static void ZEND_FASTCALL zend_jit_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info)
26642664
{
2665+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2666+
2667+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2668+
zend_readonly_property_modification_error(prop_info);
2669+
return;
2670+
}
2671+
26652672
zend_execute_data *execute_data = EG(current_execute_data);
26662673
zval tmp;
26672674

@@ -2685,6 +2692,13 @@ static void ZEND_FASTCALL zend_jit_inc_typed_prop(zval *var_ptr, zend_property_i
26852692

26862693
static void ZEND_FASTCALL zend_jit_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info)
26872694
{
2695+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2696+
2697+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2698+
zend_readonly_property_modification_error(prop_info);
2699+
return;
2700+
}
2701+
26882702
zend_execute_data *execute_data = EG(current_execute_data);
26892703
zval tmp;
26902704

@@ -2722,6 +2736,16 @@ static void ZEND_FASTCALL zend_jit_pre_dec_typed_prop(zval *var_ptr, zend_proper
27222736

27232737
static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
27242738
{
2739+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2740+
2741+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2742+
zend_readonly_property_modification_error(prop_info);
2743+
if (result) {
2744+
ZVAL_UNDEF(result);
2745+
}
2746+
return;
2747+
}
2748+
27252749
zend_execute_data *execute_data = EG(current_execute_data);
27262750

27272751
ZVAL_DEREF(var_ptr);
@@ -2743,6 +2767,16 @@ static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_prope
27432767

27442768
static void ZEND_FASTCALL zend_jit_post_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
27452769
{
2770+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2771+
2772+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2773+
zend_readonly_property_modification_error(prop_info);
2774+
if (result) {
2775+
ZVAL_UNDEF(result);
2776+
}
2777+
return;
2778+
}
2779+
27462780
zend_execute_data *execute_data = EG(current_execute_data);
27472781

27482782
ZVAL_DEREF(var_ptr);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification post-inc
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
$this->bar++;
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification pre-inc
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
++$this->bar;
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification post-inc with result
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
var_dump($this->bar++);
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification pre-inc with result
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
var_dump(++$this->bar);
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification post-dec
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
$this->bar--;
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification pre-dec
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
--$this->bar;
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification dec-inc with result
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
var_dump($this->bar--);
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification pre-dec with result
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
var_dump(--$this->bar);
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d

0 commit comments

Comments
 (0)