Skip to content

Commit ebf2abf

Browse files
committed
Fix phpGH-18480: array_splice overflow on array length with offset.
1 parent 9c555f5 commit ebf2abf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ext/standard/array.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -3252,17 +3252,17 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
32523252

32533253
/* If hash for removed entries exists, go until offset+length and copy the entries to it */
32543254
if (removed != NULL) {
3255-
for ( ; pos < offset + length && idx < in_hash->nNumUsed; idx++, entry++) {
3255+
for ( ; length <= ZEND_LONG_MAX - offset && pos < offset + length && idx < in_hash->nNumUsed; idx++, entry++) {
32563256
if (Z_TYPE_P(entry) == IS_UNDEF) continue;
32573257
pos++;
32583258
Z_TRY_ADDREF_P(entry);
32593259
zend_hash_next_index_insert_new(removed, entry);
32603260
zend_hash_packed_del_val(in_hash, entry);
32613261
}
32623262
} else { /* otherwise just skip those entries */
3263-
int pos2 = pos;
3263+
zend_long pos2 = pos;
32643264

3265-
for ( ; pos2 < offset + length && idx < in_hash->nNumUsed; idx++, entry++) {
3265+
for ( ; length <= ZEND_LONG_MAX - offset && pos2 < offset + length && idx < in_hash->nNumUsed; idx++, entry++) {
32663266
if (Z_TYPE_P(entry) == IS_UNDEF) continue;
32673267
pos2++;
32683268
zend_hash_packed_del_val(in_hash, entry);

0 commit comments

Comments
 (0)