-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix PHP 8.5 recursive tokenization during token_get_all
#19547
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
Closed
+67
−0
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a55bf78
Add test showing current behaviour
kubawerlos 43a7a9a
Update test and add fix by `arnaud-lb`
kubawerlos 101cb54
Update ext/tokenizer/tests/gh19507.phpt
kubawerlos 1126337
Review updates
kubawerlos 09bda24
Fix `Zend/zend_language_scanner.l`
kubawerlos cc20668
Merge branch 'master' into fix_19507
kubawerlos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,7 @@ void shutdown_scanner(void) | |
zend_ptr_stack_destroy(&SCNG(heredoc_label_stack)); | ||
SCNG(heredoc_scan_ahead) = 0; | ||
SCNG(on_event) = NULL; | ||
SCNG(on_event_context) = NULL; | ||
} | ||
|
||
ZEND_API void zend_save_lexical_state(zend_lex_state *lex_state) | ||
|
@@ -581,6 +582,8 @@ ZEND_API zend_result open_file_for_scanning(zend_file_handle *file_handle) | |
zend_set_compiled_filename(compiled_filename); | ||
zend_string_release_ex(compiled_filename, 0); | ||
|
||
SCNG(on_event) = NULL; | ||
SCNG(on_event_context) = NULL; | ||
RESET_DOC_COMMENT(); | ||
CG(zend_lineno) = 1; | ||
CG(increment_lineno) = 0; | ||
|
@@ -766,6 +769,8 @@ ZEND_API void zend_prepare_string_for_scanning(zval *str, zend_string *filename) | |
zend_set_compiled_filename(filename); | ||
CG(zend_lineno) = 1; | ||
CG(increment_lineno) = 0; | ||
SCNG(on_event) = NULL; | ||
SCNG(on_event_context) = NULL; | ||
RESET_DOC_COMMENT(); | ||
} | ||
|
||
|
@@ -1636,6 +1641,9 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ | |
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("integer"){TABS_AND_SPACES}")" { | ||
if (PARSER_MODE()) { | ||
zend_error(E_DEPRECATED, "Non-canonical cast (integer) is deprecated, use the (int) cast instead"); | ||
if (PARSER_MODE() && EG(exception)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
RETURN_TOKEN(T_ERROR); | ||
} | ||
} | ||
RETURN_TOKEN(T_INT_CAST); | ||
} | ||
|
@@ -1647,6 +1655,9 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ | |
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("double"){TABS_AND_SPACES}")" { | ||
if (PARSER_MODE()) { | ||
zend_error(E_DEPRECATED, "Non-canonical cast (double) is deprecated, use the (float) cast instead"); | ||
if (PARSER_MODE() && EG(exception)) { | ||
RETURN_TOKEN(T_ERROR); | ||
} | ||
} | ||
RETURN_TOKEN(T_DOUBLE_CAST); | ||
} | ||
|
@@ -1666,6 +1677,9 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ | |
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("binary"){TABS_AND_SPACES}")" { | ||
if (PARSER_MODE()) { | ||
zend_error(E_DEPRECATED, "Non-canonical cast (binary) is deprecated, use the (string) cast instead"); | ||
if (PARSER_MODE() && EG(exception)) { | ||
RETURN_TOKEN(T_ERROR); | ||
} | ||
} | ||
RETURN_TOKEN(T_STRING_CAST); | ||
} | ||
|
@@ -1685,6 +1699,9 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ | |
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("boolean"){TABS_AND_SPACES}")" { | ||
if (PARSER_MODE()) { | ||
zend_error(E_DEPRECATED, "Non-canonical cast (boolean) is deprecated, use the (bool) cast instead"); | ||
if (PARSER_MODE() && EG(exception)) { | ||
RETURN_TOKEN(T_ERROR); | ||
} | ||
} | ||
RETURN_TOKEN(T_BOOL_CAST); | ||
} | ||
|
@@ -2741,6 +2758,7 @@ skip_escape_conversion: | |
SCNG(heredoc_scan_ahead) = 1; | ||
SCNG(heredoc_indentation) = 0; | ||
SCNG(heredoc_indentation_uses_spaces) = 0; | ||
SCNG(on_event_context) = NULL; | ||
LANG_SCNG(on_event) = NULL; | ||
CG(doc_comment) = NULL; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--TEST-- | ||
GH-19507: Corrupted result after recursive tokenization during token_get_all() (error handler with eval) | ||
--EXTENSIONS-- | ||
tokenizer | ||
--FILE-- | ||
<?php | ||
|
||
set_error_handler(function (int $errno, string $msg) { | ||
eval('123;'); | ||
echo 'error handler called: ', $msg, "\n"; | ||
}); | ||
|
||
|
||
$tokens = PhpToken::tokenize('<?php (double) $x;', TOKEN_PARSE); | ||
foreach ($tokens as $token) { | ||
echo $token->getTokenName(), "\n"; | ||
} | ||
?> | ||
--EXPECT-- | ||
error handler called: Non-canonical cast (double) is deprecated, use the (float) cast instead | ||
T_OPEN_TAG | ||
T_DOUBLE_CAST | ||
T_WHITESPACE | ||
T_VARIABLE | ||
; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--TEST-- | ||
GH-19507: Corrupted result after recursive tokenization during token_get_all() (error handler with throw) | ||
--EXTENSIONS-- | ||
tokenizer | ||
--FILE-- | ||
<?php | ||
|
||
set_error_handler(function (int $errno, string $msg) { | ||
throw new RuntimeException('error handler called: ' . $msg); | ||
}); | ||
|
||
|
||
$tokens = PhpToken::tokenize('<?php (double) $x;', TOKEN_PARSE); | ||
foreach ($tokens as $token) { | ||
echo $token->getTokenName(), "\n"; | ||
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught RuntimeException: error handler called: Non-canonical cast (double) is deprecated, use the (float) cast instead in %s:%d | ||
Stack trace: | ||
#0 [internal function]: {closure:%s:%d}(%d, 'Non-canonical c...', '', 1) | ||
#1 %s(%d): PhpToken::tokenize('<?php (double) ...', %d) | ||
#2 {main} | ||
thrown in %s on line %d |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also reset
SCNG(on_event_context)
here:php-src/Zend/zend_language_scanner.l
Line 2761 in 43a7a9a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (I hope).