Skip to content

Commit 72a163a

Browse files
authored
Add stack limit check in zend_eval_const_expr() (#11424)
1 parent aa87793 commit 72a163a

File tree

2 files changed

+143
-7
lines changed

2 files changed

+143
-7
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
--TEST--
2+
Stack limit 013 - Internal stack limit check in zend_eval_const_expr()
3+
--SKIPIF--
4+
<?php
5+
if (!function_exists('zend_test_zend_call_stack_get')) die("skip zend_test_zend_call_stack_get() is not available");
6+
?>
7+
--EXTENSIONS--
8+
zend_test
9+
--INI--
10+
zend.max_allowed_stack_size=64K
11+
--FILE--
12+
<?php
13+
14+
$test = [
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~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+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116+
1
117+
];
118+
119+
--EXPECTF--
120+
Fatal error: Maximum call stack size of %d bytes reached during compilation. Try splitting expression in %s on line %d

Zend/zend_compile.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ static void zend_compile_expr(znode *result, zend_ast *ast);
9999
static void zend_compile_stmt(zend_ast *ast);
100100
static void zend_compile_assign(znode *result, zend_ast *ast);
101101

102+
#ifdef ZEND_CHECK_STACK_LIMIT
103+
zend_never_inline static void zend_stack_limit_error(void)
104+
{
105+
zend_error_noreturn(E_COMPILE_ERROR,
106+
"Maximum call stack size of %zu bytes reached during compilation. Try splitting expression",
107+
(size_t) ((uintptr_t) EG(stack_base) - (uintptr_t) EG(stack_limit)));
108+
}
109+
110+
static void zend_check_stack_limit(void)
111+
{
112+
if (UNEXPECTED(zend_call_stack_overflowed(EG(stack_limit)))) {
113+
zend_stack_limit_error();
114+
}
115+
}
116+
#else /* ZEND_CHECK_STACK_LIMIT */
117+
static void zend_check_stack_limit(void)
118+
{
119+
}
120+
#endif /* ZEND_CHECK_STACK_LIMIT */
121+
102122
static void init_op(zend_op *op)
103123
{
104124
MAKE_NOP(op);
@@ -10550,13 +10570,7 @@ static void zend_compile_expr_inner(znode *result, zend_ast *ast) /* {{{ */
1055010570

1055110571
static void zend_compile_expr(znode *result, zend_ast *ast)
1055210572
{
10553-
#ifdef ZEND_CHECK_STACK_LIMIT
10554-
if (UNEXPECTED(zend_call_stack_overflowed(EG(stack_limit)))) {
10555-
zend_error_noreturn(E_COMPILE_ERROR,
10556-
"Maximum call stack size of %zu bytes reached during compilation. Try splitting expression",
10557-
(size_t) ((uintptr_t) EG(stack_base) - (uintptr_t) EG(stack_limit)));
10558-
}
10559-
#endif /* ZEND_CHECK_STACK_LIMIT */
10573+
zend_check_stack_limit();
1056010574

1056110575
uint32_t checkpoint = zend_short_circuiting_checkpoint();
1056210576
zend_compile_expr_inner(result, ast);
@@ -10642,6 +10656,8 @@ static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
1064210656
return;
1064310657
}
1064410658

10659+
zend_check_stack_limit();
10660+
1064510661
switch (ast->kind) {
1064610662
case ZEND_AST_BINARY_OP:
1064710663
zend_eval_const_expr(&ast->child[0]);

0 commit comments

Comments
 (0)