Skip to content

Commit

Permalink
Don't stop reading if fread returns an empty string (#20)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ziyann committed Mar 13, 2024
1 parent b04e520 commit b9d1f53
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ZipStreamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b9d1f53

Please sign in to comment.