From 3b5ddb417c9811a6a57e2af0f379e088e71e84a4 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 23 Feb 2016 17:53:19 +0100 Subject: [PATCH 1/2] Copy into local file Using the Guzzle stream directly here will only return 1739 characters for `fread` instead of all data. This leads to the problem that the stream is read incorrectly and thus the data cannot be properly decrypted => :bomb: This approach copies the data into a local temporary file, as done before in all stable releases as well as other storage connectors. While this approach will load the whole file into memory, this is already was has happened before in any stable release as well. See https://github.com/owncloud/core/commit/d608c37c90c308d0518d854de908ec4be5f462dc for the breaking change. To test this enable Google Drive as external storage and upload some files with encryption enabled. Reading the file should fail now. Fixes https://github.com/owncloud/core/issues/22590 --- apps/files_external/lib/google.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index ee7a73836157..982fa6bb48f1 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -33,6 +33,7 @@ namespace OC\Files\Storage; +use GuzzleHttp\Exception\RequestException; use Icewind\Streams\IteratorDirectory; set_include_path(get_include_path().PATH_SEPARATOR. @@ -439,9 +440,10 @@ public function fopen($path, $mode) { // the library's service doesn't support streaming, so we use Guzzle instead $client = \OC::$server->getHTTPClientService()->newClient(); try { - $response = $client->get($downloadUrl, [ + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); + $client->get($downloadUrl, [ 'headers' => $httpRequest->getRequestHeaders(), - 'stream' => true + 'save_to' => $tmpFile, ]); } catch (RequestException $e) { if ($e->getResponse()->getStatusCode() === 404) { @@ -451,7 +453,7 @@ public function fopen($path, $mode) { } } - return $response->getBody(); + return fopen($tmpFile, 'r'); } } return false; From aebb900cd45a38ba9e7f6dfd6217e83e260dc40f Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 25 Feb 2016 10:12:31 +0100 Subject: [PATCH 2/2] More error handling --- apps/files_external/lib/google.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index 982fa6bb48f1..3e8b60d33df7 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -446,8 +446,12 @@ public function fopen($path, $mode) { 'save_to' => $tmpFile, ]); } catch (RequestException $e) { - if ($e->getResponse()->getStatusCode() === 404) { - return false; + if(!is_null($e->getResponse())) { + if ($e->getResponse()->getStatusCode() === 404) { + return false; + } else { + throw $e; + } } else { throw $e; }