Skip to content

Commit

Permalink
Copy into local file
Browse files Browse the repository at this point in the history
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 => 💣

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 d608c37 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 #22590
  • Loading branch information
LukasReschke committed Feb 25, 2016
1 parent 32f4bea commit 3b5ddb4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions apps/files_external/lib/google.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace OC\Files\Storage;

use GuzzleHttp\Exception\RequestException;
use Icewind\Streams\IteratorDirectory;

set_include_path(get_include_path().PATH_SEPARATOR.
Expand Down Expand Up @@ -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) {
Expand All @@ -451,7 +453,7 @@ public function fopen($path, $mode) {
}
}

return $response->getBody();
return fopen($tmpFile, 'r');
}
}
return false;
Expand Down

0 comments on commit 3b5ddb4

Please sign in to comment.