[php-src] master: Merge branch 'PHP-8.6'
| From: | ndossche | Date: | Fri, 25 Sep 2026 08:19:02 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141527@lists.php.net to get a copy of this message | ||
Author: ndossche (ndossche)
Date: 2026-09-25T10:18:50+02:00
Commit: https://github.com/php/php-src/commit/ffce4afc6e0cfe32161f2d95b6d4d277d69b7c4a
Raw diff: https://github.com/php/php-src/commit/ffce4afc6e0cfe32161f2d95b6d4d277d69b7c4a.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Fix call_stack buffer overflow in zend_analyze_calls()
Changed paths:
A ext/opcache/tests/opt/call_graph_stack_overflow.phpt
M Zend/Optimizer/zend_call_graph.c
Diff:
diff --git a/Zend/Optimizer/zend_call_graph.c b/Zend/Optimizer/zend_call_graph.c
index b67f57cf041d..fe8049be7e38 100644
--- a/Zend/Optimizer/zend_call_graph.c
+++ b/Zend/Optimizer/zend_call_graph.c
@@ -50,7 +50,10 @@ ZEND_API void zend_analyze_calls(zend_arena **arena, zend_script *script, uint32
ALLOCA_FLAG(use_heap);
bool is_prototype;
- call_stack = do_alloca((op_array->last / 2) * sizeof(zend_call_info*), use_heap);
+ // Note: Reserve one call stack slot per operation. Each opcode pushes at
+ // most one entry to the call stack, and (with dead code elimination) it's
+ // possible to never pop from the stack.
+ call_stack = do_alloca(op_array->last * sizeof(zend_call_info*), use_heap);
call_info = NULL;
while (opline != end) {
switch (opline->opcode) {
diff --git a/ext/opcache/tests/opt/call_graph_stack_overflow.phpt
b/ext/opcache/tests/opt/call_graph_stack_overflow.phpt
new file mode 100644
index 000000000000..2044daf06c8d
--- /dev/null
+++ b/ext/opcache/tests/opt/call_graph_stack_overflow.phpt
@@ -0,0 +1,17 @@
+--TEST--
+zend_analyze_calls(): call_stack overflow when dead code elimination removed the DO_FCALLs
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=0x7FFEBFFF
+--FILE--
+<?php
+function test() {
+ new A(new B(new C(new D(match ([]) { 1 => 2 }))));
+}
+echo "OK\n";
+?>
+--EXPECT--
+OK