Merge pull request #19806 from owncloud/fix_19572

only wrap source if fopen was successful
This commit is contained in:
Thomas Müller 2015-10-15 19:57:24 +02:00
commit 08cc60acba
1 changed files with 11 additions and 4 deletions

View File

@ -195,9 +195,13 @@ class Encryption extends Wrapper {
public function file_put_contents($path, $data) { public function file_put_contents($path, $data) {
// file put content will always be translated to a stream write // file put content will always be translated to a stream write
$handle = $this->fopen($path, 'w'); $handle = $this->fopen($path, 'w');
$written = fwrite($handle, $data); if (is_resource($handle)) {
fclose($handle); $written = fwrite($handle, $data);
return $written; fclose($handle);
return $written;
}
return false;
} }
/** /**
@ -320,7 +324,7 @@ class Encryption extends Wrapper {
* *
* @param string $path * @param string $path
* @param string $mode * @param string $mode
* @return resource * @return resource|bool
* @throws GenericEncryptionException * @throws GenericEncryptionException
* @throws ModuleDoesNotExistsException * @throws ModuleDoesNotExistsException
*/ */
@ -404,6 +408,9 @@ class Encryption extends Wrapper {
if ($shouldEncrypt === true && $encryptionModule !== null) { if ($shouldEncrypt === true && $encryptionModule !== null) {
$headerSize = $this->getHeaderSize($path); $headerSize = $this->getHeaderSize($path);
$source = $this->storage->fopen($path, $mode); $source = $this->storage->fopen($path, $mode);
if (!is_resource($source)) {
return false;
}
$handle = \OC\Files\Stream\Encryption::wrap($source, $path, $fullPath, $header, $handle = \OC\Files\Stream\Encryption::wrap($source, $path, $fullPath, $header,
$this->uid, $encryptionModule, $this->storage, $this, $this->util, $this->fileHelper, $mode, $this->uid, $encryptionModule, $this->storage, $this, $this->util, $this->fileHelper, $mode,
$size, $unencryptedSize, $headerSize); $size, $unencryptedSize, $headerSize);