Skip to content

Commit 3661c19

Browse files
committed
Fix array cast type inference wrt packed arrays
Use KEY_LONG instead of PACKED if it's possible for the array to be empty. It won't be packed in that case. Fixes oss-fuzz #39650.
1 parent f455894 commit 3661c19

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,8 +2534,8 @@ static zend_always_inline int _zend_update_type_info(
25342534
}
25352535
if (t1 & MAY_BE_OBJECT) {
25362536
tmp |= MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
2537-
} else {
2538-
tmp |= ((t1 & (MAY_BE_ANY - MAY_BE_NULL)) << MAY_BE_ARRAY_SHIFT) | ((t1 & (MAY_BE_ANY - MAY_BE_NULL)) ? MAY_BE_ARRAY_PACKED : 0);
2537+
} else if (t1 & (MAY_BE_ANY - MAY_BE_NULL)) {
2538+
tmp |= ((t1 & (MAY_BE_ANY - MAY_BE_NULL)) << MAY_BE_ARRAY_SHIFT) | ((t1 & MAY_BE_NULL) ? MAY_BE_ARRAY_KEY_LONG : MAY_BE_ARRAY_PACKED);
25392539
}
25402540
}
25412541
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);

ext/opcache/tests/jit/cast_002.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
JIT CAST: 002
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
function test(?int $i) {
11+
$a = (array) $i;
12+
$a[-1] = 1;
13+
var_dump($a);
14+
}
15+
test(null);
16+
?>
17+
--EXPECT--
18+
array(1) {
19+
[-1]=>
20+
int(1)
21+
}

0 commit comments

Comments
 (0)