Skip to content

Commit 40236a5

Browse files
authored
Merge pull request #54628 from nextcloud/backport/54607/stable31
[stable31] fix(encryption): Fix TypeError when trying to decrypt unencrypted file
2 parents 9ba1aae + ae080bf commit 40236a5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/private/Files/Storage/Wrapper/Encryption.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ private function copyBetweenStorage(
671671
}
672672
}
673673
} else {
674+
$source = false;
675+
$target = false;
674676
try {
675677
$source = $sourceStorage->fopen($sourceInternalPath, 'r');
676678
$target = $this->fopen($targetInternalPath, 'w');
@@ -680,10 +682,10 @@ private function copyBetweenStorage(
680682
[, $result] = \OC_Helper::streamCopy($source, $target);
681683
}
682684
} finally {
683-
if (isset($source) && $source !== false) {
685+
if ($source !== false) {
684686
fclose($source);
685687
}
686-
if (isset($target) && $target !== false) {
688+
if ($target !== false) {
687689
fclose($target);
688690
}
689691
}

tests/lib/Files/ViewTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,9 @@ private function doTestCopyRenameFail($operation) {
11851185
$storage2->method('writeStream')
11861186
->willThrowException(new GenericFileException('Failed to copy stream'));
11871187

1188+
$storage2->method('fopen')
1189+
->willReturn(false);
1190+
11881191
$storage1->mkdir('sub');
11891192
$storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH');
11901193
$storage1->mkdir('dirtomove');

0 commit comments

Comments
 (0)