Skip to content

Commit 3529508

Browse files
committed
Fix GHSA-h96m-rvf9-jgm2
1 parent ecf82e7 commit 3529508

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
@@ -4154,7 +4154,7 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
41544154
uint32_t argc, i;
41554155
zval *src_entry;
41564156
HashTable *src, *dest;
4157-
uint32_t count = 0;
4157+
uint64_t count = 0;
41584158

41594159
ZEND_PARSE_PARAMETERS_START(0, -1)
41604160
Z_PARAM_VARIADIC('+', args, argc)
@@ -4174,6 +4174,11 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
41744174
count += zend_hash_num_elements(Z_ARRVAL_P(arg));
41754175
}
41764176

4177+
if (UNEXPECTED(count >= HT_MAX_SIZE)) {
4178+
zend_throw_error(NULL, "The total number of elements must be lower than %u", HT_MAX_SIZE);
4179+
RETURN_THROWS();
4180+
}
4181+
41774182
if (argc == 2) {
41784183
zval *ret = NULL;
41794184

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)