Skip to content

Fix OSS-Fuzz #416302790 #18537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Zend/tests/constants/oss_fuzz_416302790.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
OSS-Fuzz #416302790
--FILE--
<?php
function x(){
#[Attr] const X = 1;
}
?>
--EXPECTF--
Parse error: syntax error, unexpected token "const" in %s on line %d
10 changes: 7 additions & 3 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%type <ast> isset_variable type return_type type_expr type_without_static
%type <ast> identifier type_expr_without_static union_type_without_static_element union_type_without_static intersection_type_without_static
%type <ast> inline_function union_type_element union_type intersection_type
%type <ast> attributed_statement attributed_class_statement attributed_parameter
%type <ast> attributed_statement attributed_top_statement attributed_class_statement attributed_parameter
%type <ast> attribute_decl attribute attributes attribute_group namespace_declaration_name
%type <ast> match match_arm_list non_empty_match_arm_list match_arm match_arm_cond_list
%type <ast> enum_declaration_statement enum_backing_type enum_case enum_case_expr
Expand Down Expand Up @@ -391,13 +391,17 @@ attributed_statement:
| trait_declaration_statement { $$ = $1; }
| interface_declaration_statement { $$ = $1; }
| enum_declaration_statement { $$ = $1; }
;

attributed_top_statement:
attributed_statement { $$ = $1; }
| T_CONST const_list ';' { $$ = $2; }
;

top_statement:
statement { $$ = $1; }
| attributed_statement { $$ = $1; }
| attributes attributed_statement { $$ = zend_ast_with_attributes($2, $1); }
| attributed_top_statement { $$ = $1; }
| attributes attributed_top_statement { $$ = zend_ast_with_attributes($2, $1); }
| T_HALT_COMPILER '(' ')' ';'
{ $$ = zend_ast_create(ZEND_AST_HALT_COMPILER,
zend_ast_create_zval_from_long(zend_get_scanned_file_offset()));
Expand Down