Skip to content

Commit a7f2a15

Browse files
committed
1 parent 501b15e commit a7f2a15

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
@@ -4272,7 +4272,7 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
42724272
uint32_t argc, i;
42734273
zval *src_entry;
42744274
HashTable *src, *dest;
4275-
uint32_t count = 0;
4275+
uint64_t count = 0;
42764276

42774277
ZEND_PARSE_PARAMETERS_START(0, -1)
42784278
Z_PARAM_VARIADIC('+', args, argc)
@@ -4292,6 +4292,11 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
42924292
count += zend_hash_num_elements(Z_ARRVAL_P(arg));
42934293
}
42944294

4295+
if (UNEXPECTED(count >= HT_MAX_SIZE)) {
4296+
zend_throw_error(NULL, "The total number of elements must be lower than %u", HT_MAX_SIZE);
4297+
RETURN_THROWS();
4298+
}
4299+
42954300
if (argc == 2) {
42964301
zval *ret = NULL;
42974302

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)