Repository navigation
Conversation
…n parse_file() ast\parse_file() held zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, ...) across stream open, read, and close without blocking fiber switches or catching bailouts, and proceeded into get_ast() even when stream read or close threw an exception. Wrap stream I/O in zend_fiber_switch_block()/unblock() (PHP >= 8.1) and zend_try/zend_catch so error handling and fiber switching are always restored and any copied buffer is freed on bailout. Check EG(exception) before calling get_ast(), avoid inspecting the stream pointer after closing, and throw RuntimeException if opening fails without setting an exception.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Before
PHP_FUNCTION(parse_file)heldzend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling)acrossphp_stream_open_wrapper_ex(),php_stream_copy_to_mem(), andphp_stream_close(). Because userland stream wrappers can run inside those calls:Fiberinside a stream wrapper switched fibers whileEH_THROWwas active (fibers do not save/restoreEG(error_handling)), leakingEH_THROWto other fibers and allowingparse_file()to return without throwing.zend_bailout()) during stream I/O skippedzend_restore_error_handling(), leavingEH_THROWactive during shutdown functions.parse_file()to enterget_ast()withEG(exception)already set (trippingzendlex()'s debug assertion and chaining aParseErroron invalid input).EG(exception)(such as under PHP 8.6StreamErrorMode::Silentviastream_context_get_default()),parse_file()returnednulldespite its non-nullable\ast\Nodereturn type.After
zend_fiber_switch_block()/zend_fiber_switch_unblock()on PHP 8.1+ andzend_try/zend_catch, releasing any copiedcodebuffer and restoring error handling and fiber switching before re-invokingzend_bailout().php_stream *streaminside thezend_tryblock and tracked open success viavolatile zend_bool openedso the closed stream pointer is never inspected afterphp_stream_close().RuntimeExceptionwhen opening fails withEG(exception) == NULL, and aborted beforeget_ast()(freeingcode) wheneverEG(exception)is set after stream read or close.Scope rationale
PHP_FUNCTION(parse_file)stream I/O lifecycle;parse_code()does not perform stream I/O or replace error handling.package.xml, matching repository convention for PRs.Test plan
tests/parse_file_fiber.phpt,tests/parse_file_stream_exception.phpt,tests/parse_file_bailout_error_handling.phpt, andtests/parse_file_silent_open.phpt(verified failures onmaster, including leakedEH_THROWandzendlex()abort)-Wall -Wextra -Wno-unused-parameter -Werror(zero-Wclobberedwarnings) and passed full test suite on PHP 7.4 debug, 8.4 ASan NTS/ZTS, 8.5 debug/release, and 8.6 debugrun-tests.php -m) on the new PHP 8.5-applicable tests: 0 errors, 0 leakspecl packagesucceeds