Skip to content

Commit

Permalink
Merge pull request #11555 from nextcloud/backport/11435/stable14
Browse files Browse the repository at this point in the history
throw an error if a node is smaller than expected in assemblystream
  • Loading branch information
rullzer committed Oct 2, 2018
2 parents 27323c9 + 90fa659 commit 5d0946a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/dav/lib/Upload/AssemblyStream.php
Expand Up @@ -57,6 +57,9 @@ class AssemblyStream implements \Icewind\Streams\File {
/** @var int */
private $currentNode = 0;

/** @var int */
private $currentNodeRead = 0;

/**
* @param string $path
* @param string $mode
Expand Down Expand Up @@ -110,10 +113,16 @@ public function stream_read($count) {
do {
$data = fread($this->currentStream, $count);
$read = strlen($data);
$this->currentNodeRead += $read;

if (feof($this->currentStream)) {
fclose($this->currentStream);
$currentNodeSize = $this->nodes[$this->currentNode]->getSize();
if ($this->currentNodeRead < $currentNodeSize) {
throw new \Exception('Stream from assembly node shorter than expected, got ' . $this->currentNodeRead . ' bytes, expected ' . $currentNodeSize);
}
$this->currentNode++;
$this->currentNodeRead = 0;
if ($this->currentNode < count($this->nodes)) {
$this->currentStream = $this->getStream($this->nodes[$this->currentNode]);
} else {
Expand Down

0 comments on commit 5d0946a

Please sign in to comment.