From ff16e3dbff4031bd1d3e7340ac0b53f22c60ac44 Mon Sep 17 00:00:00 2001
From: jknockaert <jasper@knockaert.nl>
Date: Thu, 2 Apr 2015 16:17:25 +0200
Subject: [PATCH] Adjusting count on read

---
 lib/private/files/stream/encryption.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/private/files/stream/encryption.php b/lib/private/files/stream/encryption.php
index fdfe73d99c..9ef666d78e 100644
--- a/lib/private/files/stream/encryption.php
+++ b/lib/private/files/stream/encryption.php
@@ -249,9 +249,10 @@ class Encryption extends Wrapper {
 
 		// skip the header if we read the file from the beginning
 		if ($this->position === 0) {
-			parent::stream_read($this->util->getBlockSize());
+			parent::stream_read($this->util->getHeaderSize());
 		}
 
+		$count = min($count, $this->unencryptedSize - $this->position);
 		while ($count > 0) {
 			$remainingLength = $count;
 			// update the cache of the current block
-- 
GitLab