Skip to content

Commit 060df83

Browse files
committed
Fix double-compilation of arrow-function
We transform the arrow function by nesting the expression into a return statement. If we compile the arrow function twice this would be done twice, leading to a compile assertion. Fix oss-fuzz #60411 Closes GH-11632
1 parent 9c47f33 commit 060df83

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PHP NEWS
1414
(ilutov)
1515
. Fixed line number of JMP instruction over else block. (ilutov)
1616
. Fixed use-of-uninitialized-value with ??= on assert. (ilutov)
17+
. Fixed oss-fuzz #60411 (Fix double-compilation of arrow-functions). (ilutov)
1718

1819
- Curl:
1920
. Fix crash when an invalid callback function is passed to

Zend/tests/oss_fuzz_60441.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
oss-fuzz #60441 (Double compilation of arrow function)
3+
--FILE--
4+
<?php
5+
assert(fn()=>y)[y]??=y;
6+
?>
7+
--EXPECTF--
8+
Fatal error: Uncaught Error: Undefined constant "y" in %s:%d
9+
Stack trace:
10+
#0 {main}
11+
thrown in %s on line %d

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7425,7 +7425,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
74257425
zend_compile_closure_uses(uses_ast);
74267426
}
74277427

7428-
if (ast->kind == ZEND_AST_ARROW_FUNC) {
7428+
if (ast->kind == ZEND_AST_ARROW_FUNC && decl->child[2]->kind != ZEND_AST_RETURN) {
74297429
bool needs_return = true;
74307430
if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
74317431
zend_arg_info *return_info = CG(active_op_array)->arg_info - 1;

0 commit comments

Comments
 (0)