Skip to content

Commit f0cf999

Browse files
committed
Preserve key/value type invariant in range() type inference
Don't set PACKED key type if no value type is set. Fixes oss-fuzz 6718410667458560.
1 parent fabcc9a commit f0cf999

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Zend/Optimizer/zend_func_info.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static uint32_t zend_range_info(const zend_call_info *call_info, const zend_ssa
6161
uint32_t t2 = _ssa_op1_info(op_array, ssa, call_info->arg_info[1].opline,
6262
&ssa->ops[call_info->arg_info[1].opline - op_array->opcodes]);
6363
uint32_t t3 = 0;
64-
uint32_t tmp = MAY_BE_RC1 | MAY_BE_ARRAY | MAY_BE_ARRAY_PACKED;
64+
uint32_t tmp = MAY_BE_RC1 | MAY_BE_ARRAY;
6565

6666
if (call_info->num_args == 3) {
6767
t3 = _ssa_op1_info(op_array, ssa, call_info->arg_info[2].opline,
@@ -81,6 +81,9 @@ static uint32_t zend_range_info(const zend_call_info *call_info, const zend_ssa
8181
tmp |= MAY_BE_ARRAY_OF_LONG;
8282
}
8383
}
84+
if (tmp & MAY_BE_ARRAY_OF_ANY) {
85+
tmp |= MAY_BE_ARRAY_PACKED;
86+
}
8487
return tmp;
8588
} else {
8689
/* May throw */

ext/opcache/tests/invalid_array_key_type.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ function test2() {
1919
function test3() {
2020
foreach (range(0, $undef) as $v) { }
2121
}
22+
function test4() {
23+
var_dump(range(0, ~$u));
24+
}
2225

2326
?>
2427
===DONE===

0 commit comments

Comments
 (0)