Skip to content

Commit

Permalink
throw error if the length of a chunks goes beyond eof
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Feb 29, 2024
1 parent 884c6bb commit 0146067
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Reader/BufferedReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,20 @@ protected function readRaw(int $length): string
return '';
}
fseek($this->resource, $this->resourcePointer);
$rawData = fread(
$this->resource,
min(
$length,
$this->getRemainingRawLength()
)
$readLength = min(
$length,
$this->getRemainingRawLength()
);

$rawData = fread($this->resource, $readLength);
if($rawData === false) {
throw new Exception("Failed to read compressed input data.");
}

if (strlen($rawData) < $readLength && feof($this->resource)) {
throw new Exception("Reached end of file while reading compressed input data.");
}

$this->resourcePointer = ftell($this->resource) ?: $this->resourcePointer + strlen($rawData);
return $rawData;
}
Expand Down

0 comments on commit 0146067

Please sign in to comment.