handle errors from hash_final

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2022-09-02 12:27:13 +02:00
parent b1be4346cd
commit 9f5f970957
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
1 changed files with 7 additions and 2 deletions

View File

@ -69,8 +69,13 @@ class HashWrapper extends Wrapper {
if (is_callable($this->callback)) {
// if the stream is closed as a result of the end-of-request GC, the hash context might be cleaned up before this stream
if ($this->hash instanceof \HashContext) {
$hash = hash_final($this->hash);
call_user_func($this->callback, $hash);
try {
$hash = @hash_final($this->hash);
if ($hash) {
call_user_func($this->callback, $hash);
}
} catch (\Throwable $e) {
}
}
// prevent further calls by potential PHP 7 GC ghosts
$this->callback = null;