From 8a25ded7585871ce579d6439baf58c5cd0f6812b Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 8 Oct 2020 19:52:29 +0200 Subject: [PATCH 1/2] Fix undefined index and consequential damages in versions code If the user has no space and there are no versions, there won't be an `all` index in the versions entry. Hence this triggers a warning and becomes `null`, afterwards `count`, `foreach` and friends will happily throw even more warnings and errors because they don't want to play with `null`. Thus adding a fallback to an empty array. Signed-off-by: Christoph Wurst --- apps/files_versions/lib/Storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index a83ec34882..04bfa1c7c3 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -776,7 +776,7 @@ class Storage { // if still not enough free space we rearrange the versions from all files if ($availableSpace <= 0) { $result = Storage::getAllVersions($uid); - $allVersions = $result['all']; + $allVersions = $result['all'] ?? []; foreach ($result['by_file'] as $versions) { list($toDeleteNew, $size) = self::getExpireList($time, $versions, $availableSpace <= 0); From 2b1f3df3da35c7cea88dd43be575d02a1bfa6a6a Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Fri, 9 Oct 2020 15:23:10 +0200 Subject: [PATCH 2/2] Return all keys in getAllVersions() instead Signed-off-by: Morris Jobke --- apps/files_versions/lib/Storage.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index 04bfa1c7c3..43b2fef169 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -496,7 +496,7 @@ class Storage { $expiration = self::getExpiration(); $threshold = $expiration->getMaxAgeAsTimestamp(); $versions = self::getAllVersions($uid); - if (!$threshold || !array_key_exists('all', $versions)) { + if (!$threshold || empty($versions['all'])) { return; } @@ -578,7 +578,10 @@ class Storage { // newest version first krsort($versions); - $result = []; + $result = [ + 'all' => [], + 'by_file' => [], + ]; foreach ($versions as $key => $value) { $size = $view->filesize(self::VERSIONS_ROOT.'/'.$value['path'].'.v'.$value['timestamp']); @@ -775,8 +778,8 @@ class Storage { // if still not enough free space we rearrange the versions from all files if ($availableSpace <= 0) { - $result = Storage::getAllVersions($uid); - $allVersions = $result['all'] ?? []; + $result = self::getAllVersions($uid); + $allVersions = $result['all']; foreach ($result['by_file'] as $versions) { list($toDeleteNew, $size) = self::getExpireList($time, $versions, $availableSpace <= 0);