Skip to content

Commit 34e1c59

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17747: Exception on reading property in register-based FETCH_OBJ_R breaks JIT Fix GH-17745: zlib extension incorrectly handles object arguments
2 parents ac52b5b + 34d8bef commit 34e1c59

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

ext/opcache/jit/zend_jit_ir.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14733,7 +14733,11 @@ static int zend_jit_fetch_obj(zend_jit_ctx *jit,
1473314733
}
1473414734

1473514735
if (may_throw) {
14736-
zend_jit_check_exception(jit);
14736+
if (Z_MODE(res_addr) == IS_REG) {
14737+
zend_jit_check_exception_undef_result(jit, opline);
14738+
} else {
14739+
zend_jit_check_exception(jit);
14740+
}
1473714741
}
1473814742

1473914743
return 1;

ext/opcache/tests/jit/gh17747.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-17747 (Exception on reading property in register-based FETCH_OBJ_R breaks JIT)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.jit=function
7+
--FILE--
8+
<?php
9+
class C {
10+
public int $a;
11+
public function test() {
12+
var_dump($this->a);
13+
}
14+
}
15+
$test = new C;
16+
$test->test();
17+
?>
18+
--EXPECTF--
19+
Fatal error: Uncaught Error: Typed property C::$a must not be accessed before initialization in %s:%d
20+
Stack trace:
21+
#0 %s(%d): C->test()
22+
#1 {main}
23+
thrown in %s on line %d

ext/zlib/tests/gh17745.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-17745 (zlib extension incorrectly handles object arguments)
3+
--EXTENSIONS--
4+
zlib
5+
--FILE--
6+
<?php
7+
$obj = new stdClass;
8+
$obj->level = 3;
9+
var_dump(deflate_init(ZLIB_ENCODING_RAW, $obj));
10+
11+
class Options {
12+
public int $level = 3;
13+
}
14+
var_dump(deflate_init(ZLIB_ENCODING_RAW, new Options));
15+
?>
16+
--EXPECT--
17+
object(DeflateContext)#2 (0) {
18+
}
19+
object(DeflateContext)#3 (0) {
20+
}

ext/zlib/zlib.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ static bool zlib_create_dictionary_string(HashTable *options, char **dict, size_
790790
zval *option_buffer;
791791

792792
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("dictionary"))) != NULL) {
793+
ZVAL_DEINDIRECT(option_buffer);
793794
ZVAL_DEREF(option_buffer);
794795
switch (Z_TYPE_P(option_buffer)) {
795796
case IS_STRING: {
@@ -871,6 +872,7 @@ PHP_FUNCTION(inflate_init)
871872
}
872873

873874
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
875+
ZVAL_DEINDIRECT(option_buffer);
874876
window = zval_get_long(option_buffer);
875877
}
876878
if (window < 8 || window > 15) {
@@ -1089,6 +1091,7 @@ PHP_FUNCTION(deflate_init)
10891091
}
10901092

10911093
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("level"))) != NULL) {
1094+
ZVAL_DEINDIRECT(option_buffer);
10921095
level = zval_get_long(option_buffer);
10931096
}
10941097
if (level < -1 || level > 9) {
@@ -1097,6 +1100,7 @@ PHP_FUNCTION(deflate_init)
10971100
}
10981101

10991102
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("memory"))) != NULL) {
1103+
ZVAL_DEINDIRECT(option_buffer);
11001104
memory = zval_get_long(option_buffer);
11011105
}
11021106
if (memory < 1 || memory > 9) {
@@ -1105,6 +1109,7 @@ PHP_FUNCTION(deflate_init)
11051109
}
11061110

11071111
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
1112+
ZVAL_DEINDIRECT(option_buffer);
11081113
window = zval_get_long(option_buffer);
11091114
}
11101115
if (window < 8 || window > 15) {
@@ -1113,6 +1118,7 @@ PHP_FUNCTION(deflate_init)
11131118
}
11141119

11151120
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("strategy"))) != NULL) {
1121+
ZVAL_DEINDIRECT(option_buffer);
11161122
strategy = zval_get_long(option_buffer);
11171123
}
11181124
switch (strategy) {

ext/zlib/zlib.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ function gzread($stream, int $length): string|false {}
270270
*/
271271
function gzgets($stream, ?int $length = null): string|false {}
272272

273-
function deflate_init(int $encoding, array $options = []): DeflateContext|false {}
273+
function deflate_init(int $encoding, array|object $options = []): DeflateContext|false {}
274274

275275
function deflate_add(DeflateContext $context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH): string|false {}
276276

277-
function inflate_init(int $encoding, array $options = []): InflateContext|false {}
277+
function inflate_init(int $encoding, array|object $options = []): InflateContext|false {}
278278

279279
function inflate_add(InflateContext $context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH): string|false {}
280280

ext/zlib/zlib_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)