From c7883b1769eb785264abcbf84a363100ff784228 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 15 Oct 2015 12:06:49 +0200 Subject: [PATCH 1/2] only wrap source if fopen was successful --- lib/private/files/storage/wrapper/encryption.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index d6b7f53408..aade7cd8bb 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -320,7 +320,7 @@ class Encryption extends Wrapper { * * @param string $path * @param string $mode - * @return resource + * @return resource|bool * @throws GenericEncryptionException * @throws ModuleDoesNotExistsException */ @@ -404,6 +404,9 @@ class Encryption extends Wrapper { if ($shouldEncrypt === true && $encryptionModule !== null) { $headerSize = $this->getHeaderSize($path); $source = $this->storage->fopen($path, $mode); + if (!is_resource($source)) { + return false; + } $handle = \OC\Files\Stream\Encryption::wrap($source, $path, $fullPath, $header, $this->uid, $encryptionModule, $this->storage, $this, $this->util, $this->fileHelper, $mode, $size, $unencryptedSize, $headerSize); From dd6cb67030a260c94ec00770c966bc66dc24a308 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 15 Oct 2015 12:12:52 +0200 Subject: [PATCH 2/2] check if fopen was successful before continue --- lib/private/files/storage/wrapper/encryption.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index aade7cd8bb..2f0c1e35b0 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -195,9 +195,13 @@ class Encryption extends Wrapper { public function file_put_contents($path, $data) { // file put content will always be translated to a stream write $handle = $this->fopen($path, 'w'); - $written = fwrite($handle, $data); - fclose($handle); - return $written; + if (is_resource($handle)) { + $written = fwrite($handle, $data); + fclose($handle); + return $written; + } + + return false; } /**