Skip to content

Commit df93146

Browse files
committed
Fix missing readonly modification error with inc/dec in JIT
Closes GH-10746
1 parent 916b132 commit df93146

10 files changed

+236
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ PHP NEWS
5656

5757
- Opcache:
5858
. Fix incorrect page_size check. (nielsdos)
59+
. Fix readonly modification check when using inc/dec operators on readonly
60+
property with JIT. (ilutov)
5961

6062
- OpenSSL:
6163
. Fixed php_openssl_set_server_dh_param() DH params errors handling. (nielsdos)

ext/opcache/jit/zend_jit_helpers.c

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

26562656
static void ZEND_FASTCALL zend_jit_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info)
26572657
{
2658+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2659+
2660+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2661+
zend_readonly_property_modification_error(prop_info);
2662+
return;
2663+
}
2664+
26582665
zend_execute_data *execute_data = EG(current_execute_data);
26592666
zval tmp;
26602667

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

26792686
static void ZEND_FASTCALL zend_jit_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info)
26802687
{
2688+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2689+
2690+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2691+
zend_readonly_property_modification_error(prop_info);
2692+
return;
2693+
}
2694+
26812695
zend_execute_data *execute_data = EG(current_execute_data);
26822696
zval tmp;
26832697

@@ -2715,6 +2729,16 @@ static void ZEND_FASTCALL zend_jit_pre_dec_typed_prop(zval *var_ptr, zend_proper
27152729

27162730
static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
27172731
{
2732+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2733+
2734+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2735+
zend_readonly_property_modification_error(prop_info);
2736+
if (result) {
2737+
ZVAL_UNDEF(result);
2738+
}
2739+
return;
2740+
}
2741+
27182742
zend_execute_data *execute_data = EG(current_execute_data);
27192743

27202744
ZVAL_DEREF(var_ptr);
@@ -2736,6 +2760,16 @@ static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_prope
27362760

27372761
static void ZEND_FASTCALL zend_jit_post_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
27382762
{
2763+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2764+
2765+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2766+
zend_readonly_property_modification_error(prop_info);
2767+
if (result) {
2768+
ZVAL_UNDEF(result);
2769+
}
2770+
return;
2771+
}
2772+
27392773
zend_execute_data *execute_data = EG(current_execute_data);
27402774

27412775
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)