Handle undefined dim in assign_dim_helper

Not only the value can be undefined here, but the offset as well.
This commit is contained in:
Nikita Popov 2021-10-07 15:34:34 +02:00
parent 455837139e
commit 08c29a657d
2 changed files with 32 additions and 0 deletions

View File

@ -1264,6 +1264,12 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_obj_rw_helper(zval *object_ptr, zva
static void ZEND_FASTCALL zend_jit_assign_dim_helper(zval *object_ptr, zval *dim, zval *value, zval *result)
{
if (dim && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
const zend_op *opline = EG(current_execute_data)->opline;
zend_jit_undefined_op_helper(opline->op2.var);
dim = &EG(uninitialized_zval);
}
if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
const zend_op *op_data = EG(current_execute_data)->opline + 1;
ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);

View File

@ -0,0 +1,26 @@
--TEST--
JIT ASSIGN_DIM: 004
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
--FILE--
<?php
class Test implements ArrayAccess {
function offsetExists($x): bool {}
function offsetGet($x): mixed {}
function offsetSet($x, $y): void {
echo "offsetSet($x, $y)\n";
}
function offsetUnset($x): void {}
}
function test() {
$obj = new Test;
$obj[$undef] = 1;
}
test();
?>
--EXPECTF--
Warning: Undefined variable $undef in %s on line %d
offsetSet(, 1)