From f143df425a3e3a61b26df3981540461da2af84da Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 10 Nov 2023 11:00:41 +0100 Subject: [PATCH] Fix error handling in Stream::getContents() --- src/Stream.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Stream.php b/src/Stream.php index d3bd78d..24e9350 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -260,8 +260,14 @@ public function getContents(): string throw new \RuntimeException('Stream is detached'); } - if (false === $contents = @\stream_get_contents($this->stream)) { - throw new \RuntimeException('Unable to read stream contents: ' . (\error_get_last()['message'] ?? '')); + $contents = ''; + + while (!\feof($this->stream)) { + if (false === $result = @\fread($this->stream, 16372)) { + throw new \RuntimeException('Unable to read from stream: ' . (\error_get_last()['message'] ?? '')); + } + + $contents .= $result; } return $contents;