Skip to content

Commit fadceca

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17140 (Assertion failure in JIT trace exit with ZEND_FETCH_DIM_FUNC_ARG) Fix GH-16255: Unexpected nan value in ext/gd/libgd/gd_filter.c
2 parents 0507b83 + 2104097 commit fadceca

File tree

5 files changed

+126
-2
lines changed

5 files changed

+126
-2
lines changed

ext/gd/gd.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3739,7 +3739,24 @@ PHP_FUNCTION(imageconvolution)
37393739
}
37403740
}
37413741
}
3742-
res = gdImageConvolution(im_src, matrix, (float)div, (float)offset);
3742+
3743+
if (UNEXPECTED(!zend_finite(div))) {
3744+
zend_argument_value_error(3, "must be finite");
3745+
RETURN_THROWS();
3746+
}
3747+
3748+
float div_float = (float) div;
3749+
if (UNEXPECTED(div_float == 0.0f)) {
3750+
zend_argument_value_error(3, "must not be 0");
3751+
RETURN_THROWS();
3752+
}
3753+
3754+
if (UNEXPECTED(!zend_finite(offset))) {
3755+
zend_argument_value_error(4, "must be finite");
3756+
RETURN_THROWS();
3757+
}
3758+
3759+
res = gdImageConvolution(im_src, matrix, div_float, (float) offset);
37433760

37443761
if (res) {
37453762
RETURN_TRUE;

ext/gd/tests/gh16255.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
GH-16255 (Unexpected nan value in ext/gd/libgd/gd_filter.c)
3+
--EXTENSIONS--
4+
gd
5+
--CREDITS--
6+
cmb69
7+
--FILE--
8+
<?php
9+
$matrix = array(array(1, 0, 1), array(0, 5, 0), array(1, 0, 1));
10+
$im = imagecreatetruecolor(40, 40);
11+
12+
try {
13+
imageconvolution($im, $matrix, NAN, 1.0);
14+
} catch (ValueError $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
try {
19+
imageconvolution($im, $matrix, 2.225E-307, 1.0);
20+
} catch (ValueError $e) {
21+
echo $e->getMessage(), "\n";
22+
}
23+
24+
try {
25+
imageconvolution($im, $matrix, 1, NAN);
26+
} catch (ValueError $e) {
27+
echo $e->getMessage(), "\n";
28+
}
29+
30+
?>
31+
--EXPECT--
32+
imageconvolution(): Argument #3 ($divisor) must be finite
33+
imageconvolution(): Argument #3 ($divisor) must not be 0
34+
imageconvolution(): Argument #4 ($offset) must be finite

ext/opcache/jit/zend_jit_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8654,7 +8654,7 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf
86548654
if (op->opcode == ZEND_FETCH_DIM_IS || op->opcode == ZEND_FETCH_OBJ_IS) {
86558655
ZVAL_NULL(EX_VAR_NUM(i));
86568656
} else {
8657-
assert(op->opcode == ZEND_FETCH_DIM_R || op->opcode == ZEND_FETCH_LIST_R || op->opcode == ZEND_FETCH_OBJ_R);
8657+
ZEND_ASSERT(op->opcode == ZEND_FETCH_DIM_R || op->opcode == ZEND_FETCH_LIST_R || op->opcode == ZEND_FETCH_OBJ_R || op->opcode == ZEND_FETCH_DIM_FUNC_ARG || op->opcode == ZEND_FETCH_OBJ_FUNC_ARG);
86588658
repeat_last_opline = 1;
86598659
}
86608660
} else {

ext/opcache/tests/jit/gh17140_1.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
GH-17140 (Assertion failure in JIT trace exit with ZEND_FETCH_DIM_FUNC_ARG)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.jit=1254
7+
opcache.jit_buffer_size=32M
8+
opcache.jit_hot_func=1
9+
opcache.jit_hot_side_exit=1
10+
--FILE--
11+
<?php
12+
namespace Foo;
13+
function test() {
14+
$a['x'][1] = true;
15+
for ($fusion = 0; $i < 3; $i++) {
16+
var_dump($a['x'][0]);
17+
}
18+
}
19+
test();
20+
?>
21+
--EXPECTF--
22+
Warning: Undefined variable $i in %s on line %d
23+
24+
Warning: Undefined array key 0 in %s on line %d
25+
NULL
26+
27+
Warning: Undefined variable $i in %s on line %d
28+
29+
Warning: Undefined array key 0 in %s on line %d
30+
NULL
31+
32+
Warning: Undefined array key 0 in %s on line %d
33+
NULL

ext/opcache/tests/jit/gh17140_2.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
GH-17140 (Assertion failure in JIT trace exit with ZEND_FETCH_OBJ_FUNC_ARG)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.jit=1254
7+
opcache.jit_buffer_size=32M
8+
opcache.jit_hot_func=1
9+
opcache.jit_hot_side_exit=1
10+
--FILE--
11+
<?php
12+
namespace Foo;
13+
class X {
14+
public $a = 1;
15+
public $b;
16+
function __construct() {
17+
unset($this->b);
18+
}
19+
}
20+
function test() {
21+
$a['x'] = new X;
22+
for ($fusion = 0; $i < 3; $i++) {
23+
var_dump($a['x']->b);
24+
}
25+
}
26+
test();
27+
?>
28+
--EXPECTF--
29+
Warning: Undefined variable $i in %s on line %d
30+
31+
Warning: Undefined property: Foo\X::$b in %s on line %d
32+
NULL
33+
34+
Warning: Undefined variable $i in %s on line %d
35+
36+
Warning: Undefined property: Foo\X::$b in %s on line %d
37+
NULL
38+
39+
Warning: Undefined property: Foo\X::$b in %s on line %d
40+
NULL

0 commit comments

Comments
 (0)