[php-src] master: Merge branch 'PHP-8.5'

From: Date: Mon, 10 Aug 2026 08:14:31 +0000
Subject: [php-src] master: Merge branch 'PHP-8.5'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-140572@lists.php.net to get a copy of this message
Author: Arnaud Le Blanc (arnaud-lb) Date: 2026-08-10T10:09:42+02:00 Commit: https://github.com/php/php-src/commit/07dfe42f410da39fda9c79f6c798aa259a7c92aa Raw diff: https://github.com/php/php-src/commit/07dfe42f410da39fda9c79f6c798aa259a7c92aa.diff Merge branch 'PHP-8.5' * PHP-8.5: Add a stack limit check in zend_hash_compare() (#23090) Changed paths: A Zend/tests/gh23088.phpt M Zend/tests/gh18572.phpt M Zend/zend_hash.c Diff: diff --git a/Zend/tests/gh18572.phpt b/Zend/tests/gh18572.phpt index ff178ebef24f..cf45d2afaaba 100644 --- a/Zend/tests/gh18572.phpt +++ b/Zend/tests/gh18572.phpt @@ -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\?) diff --git a/Zend/tests/gh23088.phpt b/Zend/tests/gh23088.phpt new file mode 100644 index 000000000000..59153a1f2ba3 --- /dev/null +++ b/Zend/tests/gh23088.phpt @@ -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 diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index acc342bc267d..99406f9e4192 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -3221,6 +3221,13 @@ ZEND_API int zend_hash_compare(HashTable *ht1, const HashTable *ht2, compare_fun 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.

« previous php.cvs (#140572) next »