Skip to content

Commit 8b80115

Browse files
ndosschebukka
authored andcommitted
Fix GHSA-h96m-rvf9-jgm2
1 parent 727a4dd commit 8b80115

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
@@ -3771,7 +3771,7 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
37713771
int argc, i;
37723772
zval *src_entry;
37733773
HashTable *src, *dest;
3774-
uint32_t count = 0;
3774+
uint64_t count = 0;
37753775

37763776
ZEND_PARSE_PARAMETERS_START(0, -1)
37773777
Z_PARAM_VARIADIC('+', args, argc)
@@ -3791,6 +3791,11 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
37913791
count += zend_hash_num_elements(Z_ARRVAL_P(arg));
37923792
}
37933793

3794+
if (UNEXPECTED(count >= HT_MAX_SIZE)) {
3795+
zend_throw_error(NULL, "The total number of elements must be lower than %u", HT_MAX_SIZE);
3796+
RETURN_THROWS();
3797+
}
3798+
37943799
if (argc == 2) {
37953800
zval *ret = NULL;
37963801

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)