diff --git a/src/Parser/ArchiveIterator.php b/src/Parser/ArchiveIterator.php index 0db5480..cc1a0b1 100644 --- a/src/Parser/ArchiveIterator.php +++ b/src/Parser/ArchiveIterator.php @@ -57,11 +57,11 @@ public function next(): void $position = ftell($this->handle); $headerData = fread($this->handle, 512); - if (strlen($headerData) < 512) { + if ($headerData === false || strlen($headerData) < 512) { throw new InvalidArchiveFormatException( sprintf( 'Invalid TAR archive format: Unexpected end of file, returned non-block size: %d bytes', - strlen($headerData) + $headerData === false ? 0 : strlen($headerData) ) ); } @@ -91,11 +91,11 @@ public function next(): void if ($contentBlockSize > 0) { if ($this->readContent) { $blockContent = fread($this->handle, $contentBlockSize); - if (strlen($blockContent) < $contentBlockSize) { + if ($blockContent === false || strlen($blockContent) < $contentBlockSize) { throw new InvalidArchiveFormatException( sprintf( 'Invalid TAR archive format: Unexpected end of file, returned non-block size: %d bytes', - strlen($blockContent) + $blockContent === false ? 0 : strlen($blockContent) ) ); } diff --git a/src/Parser/Header.php b/src/Parser/Header.php index c8c152d..bb0397a 100644 --- a/src/Parser/Header.php +++ b/src/Parser/Header.php @@ -42,7 +42,7 @@ public function __construct(string $content) { $length = strlen($content); if ($length !== 512) { - new InvalidArgumentException(sprintf('Tar header must be 512 bytes length, %d bytes got', $length)); + throw new InvalidArgumentException(sprintf('Tar header must be 512 bytes length, %d bytes got', $length)); } $this->content = $content;