Skip to content

Commit e766378

Browse files
committed
Handle undef value in assign_dim jit
We should report the undefined variable here and convert it to null. Passing on undef is particularly insidious here, because a write_dimension handler may insert it into a hash table (observed with WeakMap).
1 parent cfb21e8 commit e766378

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,13 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_obj_rw_helper(zval *object_ptr, zva
12391239

12401240
static void ZEND_FASTCALL zend_jit_assign_dim_helper(zval *object_ptr, zval *dim, zval *value, zval *result)
12411241
{
1242+
if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
1243+
const zend_op *op_data = EG(current_execute_data)->opline + 1;
1244+
ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
1245+
zend_jit_undefined_op_helper(op_data->op1.var);
1246+
value = &EG(uninitialized_zval);
1247+
}
1248+
12421249
if (EXPECTED(Z_TYPE_P(object_ptr) == IS_OBJECT)) {
12431250
ZVAL_DEREF(value);
12441251
Z_OBJ_HT_P(object_ptr)->write_dimension(Z_OBJ_P(object_ptr), dim, value);

ext/opcache/tests/jit/assign_dim_002.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ function foo5() {
8181
}
8282
var_dump(foo5());
8383

84+
85+
function array_access_undef() {
86+
$ao = new ArrayObject;
87+
$ao[0] = $undef;
88+
var_dump($ao[0]);
89+
}
90+
91+
array_access_undef();
92+
8493
?>
8594
--EXPECTF--
8695
array(1) {
@@ -136,3 +145,6 @@ array(1) {
136145
}
137146
Cannot use a scalar value as an array
138147
int(1)
148+
149+
Warning: Undefined variable $undef in %s on line %d
150+
NULL

0 commit comments

Comments
 (0)