Skip to content

Commit fe8d4d1

Browse files
committed
Fix preloading FCC const exprs
Preloading will try to evaluate class constants during compilation, but evaluated FCCs are objects, which can not be persisted. Apply the same fix as for enums: Fail evaluation when compiling. Preloading will also reset CG(map_ptr_last) after compilation, which results in collisions if map ptrs were allocated during compilation. Move the ZEND_MAP_PTR_NEW() to the persist phase, as a shared map ptr is not necessary before that.
1 parent 3154731 commit fe8d4d1

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

Zend/zend_ast.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,12 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
10541054
case ZEND_AST_CALL:
10551055
case ZEND_AST_STATIC_CALL:
10561056
{
1057+
// Preloading will attempt to resolve constants but objects can't be stored in shm
1058+
// Aborting here to store the const AST instead
1059+
if (CG(in_compilation)) {
1060+
return FAILURE;
1061+
}
1062+
10571063
zend_function *fptr;
10581064
zend_class_entry *called_scope = NULL;
10591065
switch (ast->kind) {

Zend/zend_compile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11513,7 +11513,6 @@ static void zend_compile_const_expr_fcc(zend_ast **ast_ptr)
1151311513
if ((*args_ast)->kind != ZEND_AST_CALLABLE_CONVERT) {
1151411514
zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
1151511515
}
11516-
ZEND_MAP_PTR_NEW(((zend_ast_fcc *)*args_ast)->fptr);
1151711516

1151811517
switch ((*ast_ptr)->kind) {
1151911518
case ZEND_AST_CALL: {

ext/opcache/zend_persist.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ static zend_ast *zend_persist_ast(zend_ast *ast)
197197
node = (zend_ast *) copy;
198198
} else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
199199
zend_ast_fcc *copy = zend_shared_memdup(ast, sizeof(zend_ast_fcc));
200+
ZEND_MAP_PTR_NEW(copy->fptr);
200201
node = (zend_ast *) copy;
201202
} else if (zend_ast_is_decl(ast)) {
202203
/* Not implemented. */

0 commit comments

Comments
 (0)