Skip to content

Commit 61d4ab9

Browse files
committed
add tests
1 parent d3b74ba commit 61d4ab9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ext/standard/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3234,7 +3234,7 @@ 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) {
3237+
if (length > ZEND_LONG_MAX - offset || length < ZEND_LONG_MIN + offset) {
32383238
goto end;
32393239
}
32403240

ext/standard/tests/array/gh18480.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-18480 array_splice overflow with large offset / length values
3+
--FILE--
4+
<?php
5+
$a = [PHP_INT_MAX];
6+
$offset = PHP_INT_MAX;
7+
var_dump(array_splice($a,$offset, PHP_INT_MAX));
8+
$offset = PHP_INT_MIN;
9+
var_dump(array_splice($a,$offset, PHP_INT_MIN));
10+
--EXPECT--
11+
array(0) {
12+
}
13+
array(0) {
14+
}
15+

0 commit comments

Comments
 (0)