Repository navigation
Fix GH-25957: Segfault when a stream finalizes the HashContext during hash_update_stream() or hash_update_file() - #25958
Merged
Conversation
iliaal
reviewed
Dec 1, 2026
iliaal
left a comment
Member
There was a problem hiding this comment.
This needs user code that finalizes the context from inside a stream wrapper or filter. Fixes for that class have been going to master only (PR 22470, PR 22714), so please retarget to master and move the NEWS entry accordingly.
| try { | ||
| var_dump(hash_update_stream($ctx, $fp)); | ||
| } catch (TypeError $e) { | ||
| echo $e->getMessage(), "\n"; |
Member
There was a problem hiding this comment.
Nit: please print the exception class too (echo $e::class, ": ", $e->getMessage(), PHP_EOL;) here and in the other catch blocks, so the test pins the TypeError.
…ing hash_update_stream() or hash_update_file() hash_update_stream() and hash_update_file() checked the context only once, before the loop. A user stream wrapper or filter runs during php_stream_read() and can call hash_final(), which frees the context and sets it to NULL. The next update then used the NULL context. Check the context again after each read and throw the same error as for a finalized context. hash_update_file() closes its stream first.
thunderer
force-pushed
the
fix/hash-update-stream-finalized
branch
from
December 1, 2026 12:53
cbe74ec to
440c523
Compare
iliaal
approved these changes
Dec 1, 2026
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.
Fixes GH-25957.
hash_update_stream()andhash_update_file()check the context once, before the loop.php_stream_read()can run user code (stream_open()orstream_read()of a stream wrapper, or aphp_user_filter), andhash_final()there frees the context. The fix checks the context again after each read and throws the sameTypeErroras for a context that was finalized before the call.hash_update_file()closes its stream before it throws.