Merge pull request #54628 from nextcloud/backport/54607/stable31

[stable31] fix(encryption): Fix TypeError when trying to decrypt unencrypted file
This commit is contained in:
Côme Chilliet 2025-08-26 09:14:16 +02:00 committed by GitHub
commit 40236a5665
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -671,6 +671,8 @@ class Encryption extends Wrapper {
}
}
} else {
$source = false;
$target = false;
try {
$source = $sourceStorage->fopen($sourceInternalPath, 'r');
$target = $this->fopen($targetInternalPath, 'w');
@ -680,10 +682,10 @@ class Encryption extends Wrapper {
[, $result] = \OC_Helper::streamCopy($source, $target);
}
} finally {
if (isset($source) && $source !== false) {
if ($source !== false) {
fclose($source);
}
if (isset($target) && $target !== false) {
if ($target !== false) {
fclose($target);
}
}

View file

@ -1185,6 +1185,9 @@ class ViewTest extends \Test\TestCase {
$storage2->method('writeStream')
->willThrowException(new GenericFileException('Failed to copy stream'));
$storage2->method('fopen')
->willReturn(false);
$storage1->mkdir('sub');
$storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH');
$storage1->mkdir('dirtomove');