From d6ce45fe61c05c0779cfaa3207a538a7a5b9a04c Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 31 Mar 2014 18:36:52 +0200 Subject: Correctly read the full stream in file_get_contents When using user-defined stream wrappers, PHP will return a maximum of 8192 bytes even if more was requested. This fix uses stream_get_contents to make sure the full stream is read and not only the first 8 KB. Added unit test with a bigger test file to cover this case. --- lib/private/files/storage/common.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 2b697141515..480cf6b5c77 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -118,11 +118,8 @@ abstract class Common implements \OC\Files\Storage\Storage { if (!$handle) { return false; } - $size = $this->filesize($path); - if ($size == 0) { - return ''; - } - return fread($handle, $size); + $data = stream_get_contents($handle); + return $data; } public function file_put_contents($path, $data) { -- cgit v1.2.3 From 0067a4eac287928a70a50c925b00777d760e4ec1 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 31 Mar 2014 18:37:52 +0200 Subject: Added missing fclose in file_get_contents and file_put_contents --- lib/private/files/storage/common.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 480cf6b5c77..0ce447a5a48 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -119,13 +119,16 @@ abstract class Common implements \OC\Files\Storage\Storage { return false; } $data = stream_get_contents($handle); + fclose($handle); return $data; } public function file_put_contents($path, $data) { $handle = $this->fopen($path, "w"); $this->removeCachedFile($path); - return fwrite($handle, $data); + $count = fwrite($handle, $data); + fclose($handle); + return $count; } public function rename($path1, $path2) { -- cgit v1.2.3