From b9d1f53453a5736285facb723252ea2169dc472e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20J=C3=A1rai?= Date: Wed, 13 Mar 2024 15:30:52 +0100 Subject: [PATCH] Don't stop reading if fread returns an empty string (#20) This fixes a premature loop termination on empty string read, which can happen when reading from network streams, leading to packing truncated files silently. By explicitly checking against "false", the loop will terminate only if fread returns a failure. --- src/ZipStreamer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ZipStreamer.php b/src/ZipStreamer.php index 464bfba..e476eb6 100644 --- a/src/ZipStreamer.php +++ b/src/ZipStreamer.php @@ -356,7 +356,7 @@ private function streamFileData($stream, $compress, $level) { $compStream = DeflateStream::create($level); } - while (!feof($stream) && $data = fread($stream, self::STREAM_CHUNK_SIZE)) { + while (!feof($stream) && ($data = fread($stream, self::STREAM_CHUNK_SIZE)) !== false) { $dataLength->add(strlen($data)); hash_update($hashCtx, $data); if (COMPR::DEFLATE === $compress) {