[Pkg-owncloud-commits] [owncloud] 51/215: fix encryption header error

David Prévot taffit at moszumanska.debian.org
Tue May 5 01:01:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 735f6cc0371f5e5c5d84a5ea4189f23104302ed1
Author: jknockaert <jasper at knockaert.nl>
Date:   Tue Apr 21 14:21:53 2015 +0200

    fix encryption header error
    
    When moving back the pointer to position 0 (using stream_seek), the pointer on the encrypted stream will be moved to the position immediately after the header. Reading the header again (invoked by stream_read) will cause an error, writing the header again (invoked by stream_write) will corrupt the file. Reading/writing the header should therefore happen when opening the file rather than upon read or write. Note that a side-effect of this PR is that empty files will still get an encryp [...]
---
 lib/private/files/stream/encryption.php | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/lib/private/files/stream/encryption.php b/lib/private/files/stream/encryption.php
index 910357e..936bcb7 100644
--- a/lib/private/files/stream/encryption.php
+++ b/lib/private/files/stream/encryption.php
@@ -221,15 +221,28 @@ class Encryption extends Wrapper {
 			|| $mode === 'w+'
 			|| $mode === 'wb'
 			|| $mode === 'wb+'
+			|| $mode === 'r+'
+			|| $mode === 'rb+'
 		) {
-			// We're writing a new file so start write counter with 0 bytes
-			$this->unencryptedSize = 0;
-			$this->size = 0;
 			$this->readOnly = false;
 		} else {
 			$this->readOnly = true;
 		}
 
+		if (
+			$mode === 'w'
+			|| $mode === 'w+'
+			|| $mode === 'wb'
+			|| $mode === 'wb+'
+		) {
+			// We're writing a new file so start write counter with 0 bytes
+			$this->unencryptedSize = 0;
+			$this->writeHeader();
+			$this->size = $this->util->getHeaderSize();
+		} else {
+			parent::stream_read($this->util->getHeaderSize());
+		}
+
 		$sharePath = $this->fullPath;
 		if (!$this->storage->file_exists($this->internalPath)) {
 			$sharePath = dirname($sharePath);
@@ -250,11 +263,6 @@ class Encryption extends Wrapper {
 
 		$result = '';
 
-		// skip the header if we read the file from the beginning
-		if ($this->position === 0) {
-			parent::stream_read($this->util->getHeaderSize());
-		}
-
 //		$count = min($count, $this->unencryptedSize - $this->position);
 		while ($count > 0) {
 			$remainingLength = $count;
@@ -281,11 +289,6 @@ class Encryption extends Wrapper {
 
 	public function stream_write($data) {
 
-		if ($this->position === 0) {
-			$this->writeHeader();
-			$this->size = $this->util->getHeaderSize();
-		}
-
 		$length = 0;
 		// loop over $data to fit it in 6126 sized unencrypted blocks
 		while (strlen($data) > 0) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list