diff --git a/lib/private/Files/Stream/Encryption.php b/lib/private/Files/Stream/Encryption.php index 3c884a99ae..bdbbc8a06f 100644 --- a/lib/private/Files/Stream/Encryption.php +++ b/lib/private/Files/Stream/Encryption.php @@ -315,6 +315,23 @@ class Encryption extends Wrapper { return $result; } + + /** + * stream_read wrapper to read complete requested block + */ + private function stream_read_block($blockSize) { + $remaining = $blockSize; + $data = ""; + + do { + $chunk = parent::stream_read($remaining); + $chunk_len = strlen($chunk); + $data .= $chunk; + $remaining -= $chunk_len; + } while ( ($remaining > 0) && ($chunk_len > 0) ); + + return $data; + } public function stream_write($data) { $length = 0; @@ -470,7 +487,7 @@ class Encryption extends Wrapper { // don't try to fill the cache when trying to write at the end of the unencrypted file when it coincides with new block if ($this->cache === '' && !($this->position === $this->unencryptedSize && ($this->position % $this->unencryptedBlockSize) === 0)) { // Get the data from the file handle - $data = parent::stream_read($this->util->getBlockSize()); + $data = $this->stream_read_block($this->util->getBlockSize()); $position = (int)floor($this->position/$this->unencryptedBlockSize); $numberOfChunks = (int)($this->unencryptedSize / $this->unencryptedBlockSize); if($numberOfChunks === $position) { @@ -495,7 +512,7 @@ class Encryption extends Wrapper { * read first block to skip the header */ protected function skipHeader() { - parent::stream_read($this->headerSize); + $this->stream_read_block($this->headerSize); } /**