Skip to content

Commit f18bb24

Browse files
committed
Fix type inference for INIT_ARRAY with invalid index
Fixes oss-fuzz #42568
1 parent 1481d66 commit f18bb24

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ext/opcache/Optimizer/zend_inference.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3002,7 +3002,9 @@ static zend_always_inline int _zend_update_type_info(
30023002
if (ssa_op->result_use >= 0) {
30033003
tmp |= ssa_var_info[ssa_op->result_use].type;
30043004
}
3005-
if (opline->op1_type != IS_UNUSED) {
3005+
if (opline->op1_type != IS_UNUSED
3006+
&& (opline->op2_type == IS_UNUSED
3007+
|| (t2 & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_RESOURCE|MAY_BE_STRING)))) {
30063008
tmp |= (t1 & MAY_BE_ANY) << MAY_BE_ARRAY_SHIFT;
30073009
if (t1 & MAY_BE_UNDEF) {
30083010
tmp |= MAY_BE_ARRAY_OF_NULL;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Type inference 002: Type inference for INIT_ARRAY with invalid index
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
var_dump([[]=>&$x]);
10+
?>
11+
--EXPECTF--
12+
Fatal error: Uncaught TypeError: Illegal offset type in %sinference_002.php:2
13+
Stack trace:
14+
#0 {main}
15+
thrown in %sinference_002.php on line 2

0 commit comments

Comments
 (0)