diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php
index 43016e0892fbab9572a26fd2bdc14d8610746d31..a430e3e46170a76e13d52a1d217f0244da4abb4d 100644
--- a/lib/private/files/storage/wrapper/quota.php
+++ b/lib/private/files/storage/wrapper/quota.php
@@ -95,7 +95,7 @@ class Quota extends Wrapper {
 	public function fopen($path, $mode) {
 		$source = $this->storage->fopen($path, $mode);
 		$free = $this->free_space('');
-		if ($free >= 0 && $mode !== 'r') {
+		if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
 			return \OC\Files\Stream\Quota::wrap($source, $free);
 		} else {
 			return $source;
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index 9b14335782faa2d378a9fc96d5b5fe6caa978b2a..87bafb64d41e9f1c2784ea1d72c79e8a6b4651c4 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -59,6 +59,20 @@ class Quota extends \Test\Files\Storage\Storage {
 		$this->assertEquals('foobarqwe', $instance->file_get_contents('foo'));
 	}
 
+	public function testReturnFalseWhenFopenFailed(){
+		$failStorage = $this->getMock(
+			'\OC\Files\Storage\Local',
+			array('fopen'),
+			array(array('datadir' => $this->tmpDir)));
+		$failStorage->expects($this->any())
+			->method('fopen')
+			->will($this->returnValue(false));
+
+		$instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $failStorage, 'quota' => 1000));
+
+		$this->assertFalse($instance->fopen('failedfopen', 'r'));
+	}
+
 	public function testReturnRegularStreamOnRead(){
 		$instance = $this->getLimitedStorage(9);
 
@@ -71,6 +85,11 @@ class Quota extends \Test\Files\Storage\Storage {
 		$meta = stream_get_meta_data($stream);
 		$this->assertEquals('plainfile', $meta['wrapper_type']);
 		fclose($stream);
+
+		$stream = $instance->fopen('foo', 'rb');
+		$meta = stream_get_meta_data($stream);
+		$this->assertEquals('plainfile', $meta['wrapper_type']);
+		fclose($stream);
 	}
 
 	public function testReturnQuotaStreamOnWrite(){