Skip to content

Commit e85dd0f

Browse files
committed
Zend: Do not check offset type when using string offset as array
1 parent a479ed7 commit e85dd0f

File tree

7 files changed

+15
-80
lines changed

7 files changed

+15
-80
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/tests/offsets/string_container_offset_behaviour.phpt

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ Read:
104104
Warning: String offset cast occurred in %s on line 22
105105
string(1) "5"
106106
Read-Write:
107-
108-
Warning: String offset cast occurred in %s on line 29
109107
Cannot use assign-op operators with string offsets
110108
isset():
111109
bool(true)
@@ -124,12 +122,8 @@ Warning: String offset cast occurred in %s on line 62
124122
Warning: Uninitialized string offset %d in %s on line 62
125123
string(0) ""
126124
Nested write:
127-
128-
Warning: String offset cast occurred in %s on line 69
129125
Cannot use string offset as an array
130126
Nested Read-Write:
131-
132-
Warning: String offset cast occurred in %s on line 76
133127
Cannot use string offset as an array
134128
Nested isset():
135129
bool(false)
@@ -138,8 +132,6 @@ bool(true)
138132
Nested null coalesce:
139133
string(7) "default"
140134
Nested unset():
141-
142-
Warning: String offset cast occurred in %s on line 102
143135
Cannot use string offset as an array
144136
145137
OUTPUT;
@@ -161,8 +153,6 @@ Read:
161153
Warning: String offset cast occurred in %s on line 22
162154
string(1) "5"
163155
Read-Write:
164-
165-
Warning: String offset cast occurred in %s on line 29
166156
Cannot use assign-op operators with string offsets
167157
isset():
168158
bool(true)
@@ -179,12 +169,8 @@ Warning: String offset cast occurred in %s on line 62
179169
Warning: String offset cast occurred in %s on line 62
180170
string(1) "5"
181171
Nested write:
182-
183-
Warning: String offset cast occurred in %s on line 69
184172
Cannot use string offset as an array
185173
Nested Read-Write:
186-
187-
Warning: String offset cast occurred in %s on line 76
188174
Cannot use string offset as an array
189175
Nested isset():
190176
bool(true)
@@ -193,8 +179,6 @@ bool(false)
193179
Nested null coalesce:
194180
string(1) "5"
195181
Nested unset():
196-
197-
Warning: String offset cast occurred in %s on line 102
198182
Cannot use string offset as an array
199183
200184
OUTPUT;
@@ -220,8 +204,6 @@ Warning: String offset cast occurred in %s on line 22
220204
Warning: Uninitialized string offset %i in %s on line 22
221205
string(0) ""
222206
Read-Write:
223-
224-
Warning: String offset cast occurred in %s on line 29
225207
Cannot use assign-op operators with string offsets
226208
isset():
227209
bool(false)
@@ -242,12 +224,8 @@ Warning: String offset cast occurred in %s on line 62
242224
Warning: Uninitialized string offset %i in %s on line 62
243225
string(0) ""
244226
Nested write:
245-
246-
Warning: String offset cast occurred in %s on line 69
247227
Cannot use string offset as an array
248228
Nested Read-Write:
249-
250-
Warning: String offset cast occurred in %s on line 76
251229
Cannot use string offset as an array
252230
Nested isset():
253231
bool(false)
@@ -256,8 +234,6 @@ bool(true)
256234
Nested null coalesce:
257235
string(7) "default"
258236
Nested unset():
259-
260-
Warning: String offset cast occurred in %s on line 102
261237
Cannot use string offset as an array
262238
263239
OUTPUT;
@@ -283,8 +259,6 @@ Warning: String offset cast occurred in %s on line 22
283259
Warning: Uninitialized string offset %i in %s on line 22
284260
string(0) ""
285261
Read-Write:
286-
287-
Warning: String offset cast occurred in %s on line 29
288262
Cannot use assign-op operators with string offsets
289263
isset():
290264
@@ -309,12 +283,8 @@ Warning: String offset cast occurred in %s on line 62
309283
Warning: Uninitialized string offset %i in %s on line 62
310284
string(0) ""
311285
Nested write:
312-
313-
Warning: String offset cast occurred in %s on line 69
314286
Cannot use string offset as an array
315287
Nested Read-Write:
316-
317-
Warning: String offset cast occurred in %s on line 76
318288
Cannot use string offset as an array
319289
Nested isset():
320290
bool(false)
@@ -323,8 +293,6 @@ bool(true)
323293
Nested null coalesce:
324294
string(7) "default"
325295
Nested unset():
326-
327-
Warning: String offset cast occurred in %s on line 102
328296
Cannot use string offset as an array
329297
330298
OUTPUT;
@@ -346,8 +314,6 @@ Read:
346314
Warning: String offset cast occurred in %s on line 22
347315
string(1) "5"
348316
Read-Write:
349-
350-
Warning: String offset cast occurred in %s on line 29
351317
Cannot use assign-op operators with string offsets
352318
isset():
353319
@@ -368,12 +334,8 @@ Warning: String offset cast occurred in %s on line 62
368334
Warning: String offset cast occurred in %s on line 62
369335
string(1) "5"
370336
Nested write:
371-
372-
Warning: String offset cast occurred in %s on line 69
373337
Cannot use string offset as an array
374338
Nested Read-Write:
375-
376-
Warning: String offset cast occurred in %s on line 76
377339
Cannot use string offset as an array
378340
Nested isset():
379341
@@ -386,8 +348,6 @@ bool(false)
386348
Nested null coalesce:
387349
string(1) "5"
388350
Nested unset():
389-
390-
Warning: String offset cast occurred in %s on line 102
391351
Cannot use string offset as an array
392352
393353
OUTPUT;
@@ -402,7 +362,7 @@ Cannot access offset of type %s on string
402362
Read:
403363
Cannot access offset of type %s on string
404364
Read-Write:
405-
Cannot access offset of type %s on string
365+
Cannot use assign-op operators with string offsets
406366
isset():
407367
bool(false)
408368
empty():
@@ -414,17 +374,17 @@ Cannot unset string offsets
414374
Nested read:
415375
Cannot access offset of type %s on string
416376
Nested write:
417-
Cannot access offset of type %s on string
377+
Cannot use string offset as an array
418378
Nested Read-Write:
419-
Cannot access offset of type %s on string
379+
Cannot use string offset as an array
420380
Nested isset():
421381
Cannot access offset of type %s on string
422382
Nested empty():
423383
Cannot access offset of type %s on string
424384
Nested null coalesce:
425385
Cannot access offset of type %s on string
426386
Nested unset():
427-
Cannot unset string offsets
387+
Cannot use string offset as an array
428388
429389
OUTPUT;
430390

@@ -438,7 +398,7 @@ Cannot access offset of type string on string
438398
Read:
439399
Cannot access offset of type string on string
440400
Read-Write:
441-
Cannot access offset of type string on string
401+
Cannot use assign-op operators with string offsets
442402
isset():
443403
bool(false)
444404
empty():
@@ -450,17 +410,17 @@ Cannot unset string offsets
450410
Nested read:
451411
Cannot access offset of type string on string
452412
Nested write:
453-
Cannot access offset of type string on string
413+
Cannot use string offset as an array
454414
Nested Read-Write:
455-
Cannot access offset of type string on string
415+
Cannot use string offset as an array
456416
Nested isset():
457417
bool(false)
458418
Nested empty():
459419
bool(true)
460420
Nested null coalesce:
461421
string(7) "default"
462422
Nested unset():
463-
Cannot unset string offsets
423+
Cannot use string offset as an array
464424
465425
OUTPUT;
466426

@@ -479,8 +439,6 @@ Read:
479439
Warning: Illegal string offset %s in %s on line 22
480440
string(1) "5"
481441
Read-Write:
482-
483-
Warning: Illegal string offset %s in %s on line 29
484442
Cannot use assign-op operators with string offsets
485443
isset():
486444
bool(false)
@@ -501,12 +459,8 @@ Warning: Illegal string offset %s in %s on line 62
501459
Warning: Uninitialized string offset %d in %s on line 62
502460
string(0) ""
503461
Nested write:
504-
505-
Warning: Illegal string offset %s in %s on line 69
506462
Cannot use string offset as an array
507463
Nested Read-Write:
508-
509-
Warning: Illegal string offset %s in %s on line 76
510464
Cannot use string offset as an array
511465
Nested isset():
512466
@@ -544,8 +498,6 @@ Read:
544498
Warning: Illegal string offset %s in %s on line 22
545499
string(1) "5"
546500
Read-Write:
547-
548-
Warning: Illegal string offset %s in %s on line 29
549501
Cannot use assign-op operators with string offsets
550502
isset():
551503
bool(false)
@@ -564,12 +516,8 @@ Warning: Illegal string offset %s in %s on line 62
564516
Warning: Illegal string offset %s in %s on line 62
565517
string(1) "5"
566518
Nested write:
567-
568-
Warning: Illegal string offset %s in %s on line 69
569519
Cannot use string offset as an array
570520
Nested Read-Write:
571-
572-
Warning: Illegal string offset %s in %s on line 76
573521
Cannot use string offset as an array
574522
Nested isset():
575523

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)