Skip to content

Commit ce26917

Browse files
committed
Fixed code generation for DETCH_DIM_R
Fixes oss-fuzz #63613 and #63619
1 parent eed7474 commit ce26917

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,8 @@ ZEND_API uint32_t ZEND_FASTCALL zend_array_type_info(const zval *zv)
18761876
} ZEND_HASH_FOREACH_END();
18771877
if (HT_IS_PACKED(ht)) {
18781878
tmp &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH);
1879+
} else {
1880+
tmp &= ~MAY_BE_ARRAY_PACKED;
18791881
}
18801882
return tmp;
18811883
}

ext/opcache/jit/zend_jit_ir.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11399,9 +11399,6 @@ static int zend_jit_fetch_dimension_address_inner(zend_jit_ctx *jit,
1139911399
packed_loaded = 1;
1140011400
} else {
1140111401
bad_packed_key = 1;
11402-
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) {
11403-
jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr));
11404-
}
1140511402
}
1140611403
h = ir_CONST_LONG(val);
1140711404
} else {
@@ -11511,9 +11508,18 @@ static int zend_jit_fetch_dimension_address_inner(zend_jit_ctx *jit,
1151111508
ir_refs_add(found_inputs, ir_END());
1151211509
ir_refs_add(found_vals, ref);
1151311510
ir_IF_FALSE(if_def);
11511+
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) {
11512+
jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr));
11513+
} else if (type == BP_VAR_IS && not_found_exit_addr) {
11514+
jit_SIDE_EXIT(jit, ir_CONST_ADDR(not_found_exit_addr));
11515+
} else if (type == BP_VAR_IS && result_type_guard) {
11516+
ir_END_list(*not_found_inputs);
11517+
} else {
11518+
ir_END_list(idx_not_found_inputs);
11519+
}
1151411520
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) {
1151511521
/* perform IS_UNDEF check only after result type guard (during deoptimization) */
11516-
if (!result_type_guard || (op1_info & MAY_BE_ARRAY_NUMERIC_HASH)) {
11522+
if (!result_type_guard) {
1151711523
ir_GUARD(type_ref, ir_CONST_ADDR(exit_addr));
1151811524
}
1151911525
} else if (type == BP_VAR_IS && not_found_exit_addr) {
@@ -11530,18 +11536,7 @@ static int zend_jit_fetch_dimension_address_inner(zend_jit_ctx *jit,
1153011536
ir_IF_TRUE(if_def);
1153111537
}
1153211538
}
11533-
if (!(op1_info & MAY_BE_ARRAY_KEY_LONG) || (packed_loaded && (op1_info & MAY_BE_ARRAY_NUMERIC_HASH))) {
11534-
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) {
11535-
jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr));
11536-
} else if (type == BP_VAR_IS && not_found_exit_addr) {
11537-
jit_SIDE_EXIT(jit, ir_CONST_ADDR(not_found_exit_addr));
11538-
} else if (type == BP_VAR_IS && result_type_guard) {
11539-
ir_END_list(*not_found_inputs);
11540-
} else {
11541-
ir_END_list(idx_not_found_inputs);
11542-
}
11543-
}
11544-
if (/*!packed_loaded ||*/ (op1_info & MAY_BE_ARRAY_NUMERIC_HASH)) {
11539+
if (op1_info & MAY_BE_ARRAY_NUMERIC_HASH) {
1154511540
if (if_packed) {
1154611541
ir_IF_FALSE(if_packed);
1154711542
if_packed = IR_UNUSED;
@@ -11575,6 +11570,16 @@ static int zend_jit_fetch_dimension_address_inner(zend_jit_ctx *jit,
1157511570
} else if (packed_loaded) {
1157611571
ir_refs_add(found_inputs, ir_END());
1157711572
ir_refs_add(found_vals, ref);
11573+
} else {
11574+
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) {
11575+
jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr));
11576+
} else if (type == BP_VAR_IS && not_found_exit_addr) {
11577+
jit_SIDE_EXIT(jit, ir_CONST_ADDR(not_found_exit_addr));
11578+
} else if (type == BP_VAR_IS && result_type_guard) {
11579+
ir_END_list(*not_found_inputs);
11580+
} else {
11581+
ir_END_list(idx_not_found_inputs);
11582+
}
1157811583
}
1157911584

1158011585
if (idx_not_found_inputs) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
JIT FETCH_DIM_R: 015
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+
array(1, "" => 4)[-1];
11+
?>
12+
DONE
13+
--EXPECTF--
14+
Warning: Undefined array key -1 in %sfetch_dim_r_015.php on line 2
15+
DONE
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
JIT FETCH_DIM_R: 016
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+
[4][-1];
11+
?>
12+
DONE
13+
--EXPECTF--
14+
Warning: Undefined array key -1 in %sfetch_dim_r_016.php on line 2
15+
DONE

0 commit comments

Comments
 (0)