@@ -2361,6 +2361,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2361
2361
}
2362
2362
}
2363
2363
if (!is_list && EXPECTED (Z_TYPE_P (container ) == IS_STRING )) {
2364
+ zend_string * str = Z_STR_P (container );
2364
2365
zend_long offset ;
2365
2366
2366
2367
try_string_offset :
@@ -2386,13 +2387,33 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2386
2387
return ;
2387
2388
}
2388
2389
case IS_UNDEF :
2390
+ /* The string may be destroyed while throwing the notice.
2391
+ * Temporarily increase the refcount to detect this situation. */
2392
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE )) {
2393
+ GC_ADDREF (str );
2394
+ }
2389
2395
ZVAL_UNDEFINED_OP2 ();
2396
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE ) && GC_DELREF (str ) == 0 ) {
2397
+ zend_string_release_ex (str , 0 );
2398
+ ZVAL_NULL (result );
2399
+ return ;
2400
+ }
2390
2401
case IS_DOUBLE :
2391
2402
case IS_NULL :
2392
2403
case IS_FALSE :
2393
2404
case IS_TRUE :
2394
2405
if (type != BP_VAR_IS ) {
2406
+ /* The string may be destroyed while throwing the notice.
2407
+ * Temporarily increase the refcount to detect this situation. */
2408
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE )) {
2409
+ GC_ADDREF (str );
2410
+ }
2395
2411
zend_error (E_WARNING , "String offset cast occurred" );
2412
+ if (!(GC_FLAGS (str ) & IS_ARRAY_IMMUTABLE ) && GC_DELREF (str ) == 0 ) {
2413
+ zend_string_release_ex (str , 0 );
2414
+ ZVAL_NULL (result );
2415
+ return ;
2416
+ }
2396
2417
}
2397
2418
break ;
2398
2419
case IS_REFERENCE :
@@ -2410,7 +2431,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2410
2431
}
2411
2432
out :
2412
2433
2413
- if (UNEXPECTED (Z_STRLEN_P ( container ) < ((offset < 0 ) ? - (size_t )offset : ((size_t )offset + 1 )))) {
2434
+ if (UNEXPECTED (ZSTR_LEN ( str ) < ((offset < 0 ) ? - (size_t )offset : ((size_t )offset + 1 )))) {
2414
2435
if (type != BP_VAR_IS ) {
2415
2436
zend_error (E_WARNING , "Uninitialized string offset " ZEND_LONG_FMT , offset );
2416
2437
ZVAL_EMPTY_STRING (result );
@@ -2422,8 +2443,8 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
2422
2443
zend_long real_offset ;
2423
2444
2424
2445
real_offset = (UNEXPECTED (offset < 0 )) /* Handle negative offset */
2425
- ? (zend_long )Z_STRLEN_P ( container ) + offset : offset ;
2426
- c = (zend_uchar )Z_STRVAL_P ( container )[real_offset ];
2446
+ ? (zend_long )ZSTR_LEN ( str ) + offset : offset ;
2447
+ c = (zend_uchar )ZSTR_VAL ( str )[real_offset ];
2427
2448
2428
2449
ZVAL_CHAR (result , c );
2429
2450
}
0 commit comments