Skip to content

Commit 2f2b421

Browse files
committed
Fix segfault when preloading constant AST closure
Fixes GH-21059 Closes GH-21071
1 parent 7ec14e3 commit 2f2b421

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug GH-21029 (zend_mm_heap corrupted on Aarch64, LTO builds). (Arnaud)
7+
. Fixed bug GH-21059 (Segfault when preloading constant AST closure). (ilutov)
78

89
- Windows:
910
. Fixed compilation with clang (missing intrin.h include). (Kévin Dunglas)

Zend/zend_ast.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,12 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
11541154
}
11551155
case ZEND_AST_OP_ARRAY:
11561156
{
1157+
// Preloading will attempt to resolve constants but objects can't be stored in shm
1158+
// Aborting here to store the const AST instead
1159+
if (CG(in_compilation)) {
1160+
return FAILURE;
1161+
}
1162+
11571163
zend_function *func = (zend_function *)zend_ast_get_op_array(ast)->op_array;
11581164

11591165
zend_create_closure(result, func, scope, scope, NULL);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
class Foo {
4+
public const C = static function() {
5+
echo "Hello world\n";
6+
};
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-21059: Segfault when preloading constant AST closure
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.preload={PWD}/preload_gh21059.inc
7+
--EXTENSIONS--
8+
opcache
9+
--SKIPIF--
10+
<?php
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
13+
--FILE--
14+
<?php
15+
(Foo::C)();
16+
?>
17+
--EXPECT--
18+
Hello world

0 commit comments

Comments
 (0)