@@ -3234,6 +3234,10 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
3234
3234
/* Create and initialize output hash */
3235
3235
zend_hash_init (& out_hash , (length > 0 ? num_in - length : 0 ) + (replace ? zend_hash_num_elements (replace ) : 0 ), NULL , ZVAL_PTR_DTOR , 0 );
3236
3236
3237
+ if (length > ZEND_LONG_MAX - offset ) {
3238
+ goto end ;
3239
+ }
3240
+
3237
3241
if (HT_IS_PACKED (in_hash )) {
3238
3242
/* Start at the beginning of the input hash and copy entries to output hash until offset is reached */
3239
3243
entry = in_hash -> arPacked ;
@@ -3252,7 +3256,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
3252
3256
3253
3257
/* If hash for removed entries exists, go until offset+length and copy the entries to it */
3254
3258
if (removed != NULL ) {
3255
- for ( ; length <= ZEND_LONG_MAX - offset && pos < offset + length && idx < in_hash -> nNumUsed ; idx ++ , entry ++ ) {
3259
+ for ( ; pos < offset + length && idx < in_hash -> nNumUsed ; idx ++ , entry ++ ) {
3256
3260
if (Z_TYPE_P (entry ) == IS_UNDEF ) continue ;
3257
3261
pos ++ ;
3258
3262
Z_TRY_ADDREF_P (entry );
@@ -3262,7 +3266,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
3262
3266
} else { /* otherwise just skip those entries */
3263
3267
zend_long pos2 = pos ;
3264
3268
3265
- for ( ; length <= ZEND_LONG_MAX - offset && pos2 < offset + length && idx < in_hash -> nNumUsed ; idx ++ , entry ++ ) {
3269
+ for ( ; pos2 < offset + length && idx < in_hash -> nNumUsed ; idx ++ , entry ++ ) {
3266
3270
if (Z_TYPE_P (entry ) == IS_UNDEF ) continue ;
3267
3271
pos2 ++ ;
3268
3272
zend_hash_packed_del_val (in_hash , entry );
@@ -3368,6 +3372,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
3368
3372
}
3369
3373
}
3370
3374
3375
+ end :
3371
3376
/* replace HashTable data */
3372
3377
HT_SET_ITERATORS_COUNT (& out_hash , HT_ITERATORS_COUNT (in_hash ));
3373
3378
HT_SET_ITERATORS_COUNT (in_hash , 0 );
0 commit comments