Skip to content

Commit d3b74ba

Browse files
committed
let s try another approach and let's finish earlier
just enough to create the return value.
1 parent ebf2abf commit d3b74ba

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ext/standard/array.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,6 +3234,10 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
32343234
/* Create and initialize output hash */
32353235
zend_hash_init(&out_hash, (length > 0 ? num_in - length : 0) + (replace ? zend_hash_num_elements(replace) : 0), NULL, ZVAL_PTR_DTOR, 0);
32363236

3237+
if (length > ZEND_LONG_MAX - offset) {
3238+
goto end;
3239+
}
3240+
32373241
if (HT_IS_PACKED(in_hash)) {
32383242
/* Start at the beginning of the input hash and copy entries to output hash until offset is reached */
32393243
entry = in_hash->arPacked;
@@ -3252,7 +3256,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
32523256

32533257
/* If hash for removed entries exists, go until offset+length and copy the entries to it */
32543258
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++) {
32563260
if (Z_TYPE_P(entry) == IS_UNDEF) continue;
32573261
pos++;
32583262
Z_TRY_ADDREF_P(entry);
@@ -3262,7 +3266,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
32623266
} else { /* otherwise just skip those entries */
32633267
zend_long pos2 = pos;
32643268

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++) {
32663270
if (Z_TYPE_P(entry) == IS_UNDEF) continue;
32673271
pos2++;
32683272
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
33683372
}
33693373
}
33703374

3375+
end:
33713376
/* replace HashTable data */
33723377
HT_SET_ITERATORS_COUNT(&out_hash, HT_ITERATORS_COUNT(in_hash));
33733378
HT_SET_ITERATORS_COUNT(in_hash, 0);

0 commit comments

Comments
 (0)