Skip to content

Commit a1b05a3

Browse files
committed
Tweak $count range check of array_fill()
We fix the `UNEXPECTED(EXPECTED(…))`, which does not make sense, and replace the magic number with the respective macro. We also add a test case to verify the expected behavior for an `array_fill()` edge case. Closes GH-8804.
1 parent ff472ce commit a1b05a3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ext/standard/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,7 @@ PHP_FUNCTION(array_fill)
25982598
ZEND_PARSE_PARAMETERS_END();
25992599

26002600
if (EXPECTED(num > 0)) {
2601-
if (sizeof(num) > 4 && UNEXPECTED(EXPECTED(num > 0x7fffffff))) {
2601+
if (sizeof(num) > 4 && UNEXPECTED(num >INT_MAX)) {
26022602
zend_argument_value_error(2, "is too large");
26032603
RETURN_THROWS();
26042604
} else if (UNEXPECTED(start_key > ZEND_LONG_MAX - num + 1)) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
array_fill(): last element
3+
--FILE--
4+
<?php
5+
$a = array_fill(PHP_INT_MAX, 1, "foo");
6+
var_dump(
7+
count($a),
8+
array_key_exists(PHP_INT_MAX, $a),
9+
);
10+
try {
11+
$a[] = "bar";
12+
} catch (Error $ex) {
13+
echo $ex->getMessage(), PHP_EOL;
14+
}
15+
?>
16+
--EXPECT--
17+
int(1)
18+
bool(true)
19+
Cannot add element to the array as the next element is already occupied

0 commit comments

Comments
 (0)