From e60a829b42f0f4b74db835d8e10438a33e125051 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Mon, 20 Sep 2021 19:20:51 +0200 Subject: [PATCH 1/2] explicitly close source stream on local storage Signed-off-by: Daniel Kesselberg --- lib/private/Files/Storage/Local.php | 5 ++++- tests/lib/Files/Storage/Storage.php | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index ccd331f515f37..eea04bd867641 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -568,8 +568,11 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t public function writeStream(string $path, $stream, int $size = null): int { $result = $this->file_put_contents($path, $stream); + if (is_resource($stream)) { + fclose($stream); + } if ($result === false) { - throw new GenericFileException("Failed write steam to $path"); + throw new GenericFileException("Failed write stream to $path"); } else { return $result; } diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php index ecc2bb505380a..9fae1a8484aaa 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -658,6 +658,7 @@ public function testWriteStream() { $storage->writeStream('test.txt', $source); $this->assertTrue($storage->file_exists('test.txt')); - $this->assertEquals(file_get_contents($textFile), $storage->file_get_contents('test.txt')); + $this->assertStringEqualsFile($textFile, $storage->file_get_contents('test.txt')); + $this->assertEquals('resource (closed)', gettype($source)); } } From be3f4edf1f38b1ebfd91366334e5a3a91c63cffe Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Tue, 21 Sep 2021 17:40:19 +0200 Subject: [PATCH 2/2] explicitly close source stream on encryption storage Signed-off-by: Daniel Kesselberg --- lib/private/Files/Storage/Wrapper/Encryption.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 3c65cdbc8f660..e44b7afe6fdbf 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -926,10 +926,10 @@ protected function getHeader($path) { } $result = []; - + // first check if it is an encrypted file at all // We would do query to filecache only if we know that entry in filecache exists - + $info = $this->getCache()->get($path); if (isset($info['encrypted']) && $info['encrypted'] === true) { $firstBlock = $this->readFirstBlock($path); @@ -1033,6 +1033,7 @@ public function writeStream(string $path, $stream, int $size = null): int { // always fall back to fopen $target = $this->fopen($path, 'w'); [$count, $result] = \OC_Helper::streamCopy($stream, $target); + fclose($stream); fclose($target); return $count; }