From 3b5ddb417c9811a6a57e2af0f379e088e71e84a4 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 23 Feb 2016 17:53:19 +0100 Subject: 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 ee7a7383615..982fa6bb48f 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 @@ class Google extends \OC\Files\Storage\Common { // 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 @@ class Google extends \OC\Files\Storage\Common { } } - return $response->getBody(); + return fopen($tmpFile, 'r'); } } return false; -- cgit v1.2.3