Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.4.25

- Core:
. Fixed bug GH-23088 (Stack overflow when comparing deeply nested arrays).
(Lazizbek Ergashev)

- Date:
. Fixed leak on double DatePeriod::__construct() call. (ilutov)

Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/gh18572.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ try {
}
?>
--EXPECTREGEX--
(Maximum call stack size reached during object comparison|Nesting level too deep - recursive dependency\?)
(Maximum call stack size reached during (object )?comparison|Nesting level too deep - recursive dependency\?)
40 changes: 40 additions & 0 deletions Zend/tests/gh23088.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
GH-23088 (Stack overflow when comparing deeply nested arrays)
--SKIPIF--
<?php
if (ini_get('zend.max_allowed_stack_size') === false) {
die('skip No stack limit support');
}
if (getenv('SKIP_ASAN')) {
die('skip ASAN needs different stack limit setting due to more stack space usage');
}
?>
--INI--
zend.max_allowed_stack_size=256K
--FILE--
<?php

$a = [];
$b = [];

for ($i = 0; $i < 20000; $i++) {
$a = [$a];
$b = [$b];
}

try {
var_dump($a == $b);
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
var_dump($a === $b);
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
Maximum call stack size reached during comparison
Maximum call stack size reached during comparison
7 changes: 7 additions & 0 deletions Zend/zend_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -3214,6 +3214,13 @@ ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t co
return 0;
}

#ifdef ZEND_CHECK_STACK_LIMIT
if (UNEXPECTED(zend_call_stack_overflowed(EG(stack_limit)))) {
zend_throw_error(NULL, "Maximum call stack size reached during comparison");
return ZEND_UNCOMPARABLE;
}
#endif

/* It's enough to protect only one of the arrays.
* The second one may be referenced from the first and this may cause
* false recursion detection.
Expand Down
Loading