@@ -2484,6 +2484,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2484
2484
}
2485
2485
}
2486
2486
if (!is_list && EXPECTED (Z_TYPE_P (container ) == IS_STRING )) {
2487
+ zend_string * str = Z_STR_P (container );
2487
2488
zend_long offset ;
2488
2489
2489
2490
try_string_offset :
@@ -2509,14 +2510,34 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2509
2510
return ;
2510
2511
}
2511
2512
case IS_UNDEF :
2513
+ /* The string may be destroyed while throwing the notice.
2514
+ * Temporarily increase the refcount to detect this situation. */
2515
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE )) {
2516
+ GC_ADDREF (str );
2517
+ }
2512
2518
ZVAL_UNDEFINED_OP2 ();
2519
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE ) && GC_DELREF (str ) == 0 ) {
2520
+ zend_string_release_ex (str , 0 );
2521
+ ZVAL_NULL (result );
2522
+ return ;
2523
+ }
2513
2524
ZEND_FALLTHROUGH ;
2514
2525
case IS_DOUBLE :
2515
2526
case IS_NULL :
2516
2527
case IS_FALSE :
2517
2528
case IS_TRUE :
2518
2529
if (type != BP_VAR_IS ) {
2530
+ /* The string may be destroyed while throwing the notice.
2531
+ * Temporarily increase the refcount to detect this situation. */
2532
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE )) {
2533
+ GC_ADDREF (str );
2534
+ }
2519
2535
zend_error (E_WARNING , "String offset cast occurred" );
2536
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE ) && GC_DELREF (str ) == 0 ) {
2537
+ zend_string_release_ex (str , 0 );
2538
+ ZVAL_NULL (result );
2539
+ return ;
2540
+ }
2520
2541
}
2521
2542
break ;
2522
2543
case IS_REFERENCE :
@@ -2534,7 +2555,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2534
2555
}
2535
2556
out :
2536
2557
2537
- if (UNEXPECTED (Z_STRLEN_P ( container ) < ((offset < 0 ) ? - (size_t )offset : ((size_t )offset + 1 )))) {
2558
+ if (UNEXPECTED (ZSTR_LEN ( str ) < ((offset < 0 ) ? - (size_t )offset : ((size_t )offset + 1 )))) {
2538
2559
if (type != BP_VAR_IS ) {
2539
2560
zend_error (E_WARNING , "Uninitialized string offset " ZEND_LONG_FMT , offset );
2540
2561
ZVAL_EMPTY_STRING (result );
@@ -2546,8 +2567,8 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2546
2567
zend_long real_offset ;
2547
2568
2548
2569
real_offset = (UNEXPECTED (offset < 0 )) /* Handle negative offset */
2549
- ? (zend_long )Z_STRLEN_P ( container ) + offset : offset ;
2550
- c = (zend_uchar )Z_STRVAL_P ( container )[real_offset ];
2570
+ ? (zend_long )ZSTR_LEN ( str ) + offset : offset ;
2571
+ c = (zend_uchar )ZSTR_VAL ( str )[real_offset ];
2551
2572
2552
2573
ZVAL_CHAR (result , c );
2553
2574
}
0 commit comments