Skip to content

Commit 8c59408

Browse files
committed
Zend: Do not check offset type when using string offset as array
1 parent 36b1695 commit 8c59408

File tree

6 files changed

+7
-20
lines changed

6 files changed

+7
-20
lines changed

Zend/tests/bug24773.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Bug #24773 (unset() of integers treated as arrays causes a crash)
33
--FILE--
44
<?php
5-
$array = 'test';
6-
unset($array["lvl1"]["lvl2"]["b"]);
5+
$array = 'test';
6+
unset($array["lvl1"]["lvl2"]["b"]);
77
?>
88
--EXPECTF--
9-
Fatal error: Uncaught Error: Cannot unset string offsets in %s:%d
9+
Fatal error: Uncaught Error: Cannot use string offset as an array in %s:%d
1010
Stack trace:
1111
#0 {main}
1212
thrown in %s on line %d

Zend/tests/bug73792.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ unset($value);
1212
echo 'done';
1313
?>
1414
--EXPECTF--
15-
Warning: Illegal string offset "2bbb" in %s on line %d
16-
1715
Fatal error: Uncaught Error: Cannot create references to/from string offsets in %s:%d
1816
Stack trace:
1917
#0 {main}
20-
thrown in %sbug73792.php on line 4
18+
thrown in %s on line %d

Zend/tests/bug76534.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ $x = "foo";
1010
$y = &$x["2bar"];
1111
?>
1212
--EXPECTF--
13-
Fatal error: Uncaught Exception: Illegal string offset "2bar" in %s:%d
13+
Fatal error: Uncaught Error: Cannot create references to/from string offsets in %s:%d
1414
Stack trace:
15-
#0 %sbug76534.php(%d): {closure}(2, 'Illegal string ...', '%s', %d)
16-
#1 {main}
17-
thrown in %sbug76534.php on line %d
15+
#0 {main}
16+
thrown in %s on line %d

Zend/tests/offset_assign.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ $x['2x']['y'] += 1;
88
echo "Done\n";
99
?>
1010
--EXPECTF--
11-
Warning: Illegal string offset "2x" in %s on line %d
12-
1311
Fatal error: Uncaught Error: Cannot use string offset as an array in %soffset_assign.php:%d
1412
Stack trace:
1513
#0 {main}

Zend/zend_execute.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,6 @@ static ZEND_COLD void zend_binary_assign_op_dim_slow(zval *container, zval *dim
23222322
if (opline->op2_type == IS_UNUSED) {
23232323
zend_use_new_element_for_string();
23242324
} else {
2325-
zend_check_string_offset(dim, BP_VAR_RW EXECUTE_DATA_CC);
23262325
zend_wrong_string_offset_error();
23272326
}
23282327
} else {
@@ -2624,7 +2623,6 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
26242623
if (dim == NULL) {
26252624
zend_use_new_element_for_string();
26262625
} else {
2627-
zend_check_string_offset(dim, type EXECUTE_DATA_CC);
26282626
zend_wrong_string_offset_error();
26292627
}
26302628
ZVAL_UNDEF(result);

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,9 +1411,6 @@ static zend_always_inline void ZEND_FASTCALL zend_jit_fetch_dim_obj_helper(zval
14111411
if (!dim) {
14121412
zend_throw_error(NULL, "[] operator not supported for strings");
14131413
} else {
1414-
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
1415-
zend_check_string_offset(dim, BP_VAR_RW);
1416-
}
14171414
zend_wrong_string_offset_error();
14181415
}
14191416
ZVAL_UNDEF(result);
@@ -1601,9 +1598,6 @@ static void ZEND_FASTCALL zend_jit_assign_dim_op_helper(zval *container, zval *d
16011598
if (!dim) {
16021599
zend_throw_error(NULL, "[] operator not supported for strings");
16031600
} else {
1604-
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
1605-
zend_check_string_offset(dim, BP_VAR_RW);
1606-
}
16071601
zend_wrong_string_offset_error();
16081602
}
16091603
} else if (Z_TYPE_P(container) == IS_FALSE) {

0 commit comments

Comments
 (0)