@@ -2410,6 +2410,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2410
2410
}
2411
2411
}
2412
2412
if (!is_list && EXPECTED (Z_TYPE_P (container ) == IS_STRING )) {
2413
+ zend_string * str = Z_STR_P (container );
2413
2414
zend_long offset ;
2414
2415
2415
2416
try_string_offset :
@@ -2435,14 +2436,34 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2435
2436
return ;
2436
2437
}
2437
2438
case IS_UNDEF :
2439
+ /* The string may be destroyed while throwing the notice.
2440
+ * Temporarily increase the refcount to detect this situation. */
2441
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE )) {
2442
+ GC_ADDREF (str );
2443
+ }
2438
2444
ZVAL_UNDEFINED_OP2 ();
2445
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE ) && GC_DELREF (str ) == 0 ) {
2446
+ zend_string_release_ex (str , 0 );
2447
+ ZVAL_NULL (result );
2448
+ return ;
2449
+ }
2439
2450
ZEND_FALLTHROUGH ;
2440
2451
case IS_DOUBLE :
2441
2452
case IS_NULL :
2442
2453
case IS_FALSE :
2443
2454
case IS_TRUE :
2444
2455
if (type != BP_VAR_IS ) {
2456
+ /* The string may be destroyed while throwing the notice.
2457
+ * Temporarily increase the refcount to detect this situation. */
2458
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE )) {
2459
+ GC_ADDREF (str );
2460
+ }
2445
2461
zend_error (E_WARNING , "String offset cast occurred" );
2462
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE ) && GC_DELREF (str ) == 0 ) {
2463
+ zend_string_release_ex (str , 0 );
2464
+ ZVAL_NULL (result );
2465
+ return ;
2466
+ }
2446
2467
}
2447
2468
break ;
2448
2469
case IS_REFERENCE :
@@ -2460,7 +2481,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2460
2481
}
2461
2482
out :
2462
2483
2463
- if (UNEXPECTED (Z_STRLEN_P ( container ) < ((offset < 0 ) ? - (size_t )offset : ((size_t )offset + 1 )))) {
2484
+ if (UNEXPECTED (ZSTR_LEN ( str ) < ((offset < 0 ) ? - (size_t )offset : ((size_t )offset + 1 )))) {
2464
2485
if (type != BP_VAR_IS ) {
2465
2486
zend_error (E_WARNING , "Uninitialized string offset " ZEND_LONG_FMT , offset );
2466
2487
ZVAL_EMPTY_STRING (result );
@@ -2472,8 +2493,8 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2472
2493
zend_long real_offset ;
2473
2494
2474
2495
real_offset = (UNEXPECTED (offset < 0 )) /* Handle negative offset */
2475
- ? (zend_long )Z_STRLEN_P ( container ) + offset : offset ;
2476
- c = (zend_uchar )Z_STRVAL_P ( container )[real_offset ];
2496
+ ? (zend_long )ZSTR_LEN ( str ) + offset : offset ;
2497
+ c = (zend_uchar )ZSTR_VAL ( str )[real_offset ];
2477
2498
2478
2499
ZVAL_CHAR (result , c );
2479
2500
}
0 commit comments