Skip to content

Commit e6d7d34

Browse files
ndosscheSakiTakamachi
authored andcommitted
1 parent d521259 commit e6d7d34

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

ext/standard/array.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4281,7 +4281,7 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
42814281
uint32_t argc, i;
42824282
zval *src_entry;
42834283
HashTable *src, *dest;
4284-
uint32_t count = 0;
4284+
uint64_t count = 0;
42854285

42864286
ZEND_PARSE_PARAMETERS_START(0, -1)
42874287
Z_PARAM_VARIADIC('+', args, argc)
@@ -4301,6 +4301,11 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
43014301
count += zend_hash_num_elements(Z_ARRVAL_P(arg));
43024302
}
43034303

4304+
if (UNEXPECTED(count >= HT_MAX_SIZE)) {
4305+
zend_throw_error(NULL, "The total number of elements must be lower than %u", HT_MAX_SIZE);
4306+
RETURN_THROWS();
4307+
}
4308+
43044309
if (argc == 2) {
43054310
zval *ret = NULL;
43064311

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GHSA-h96m-rvf9-jgm2
3+
--FILE--
4+
<?php
5+
6+
$power = 20; // Chosen to be well within a memory_limit
7+
$arr = range(0, 2**$power);
8+
try {
9+
array_merge(...array_fill(0, 2**(32-$power), $arr));
10+
} catch (Error $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
The total number of elements must be lower than %d

0 commit comments

Comments
 (0)