diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2022-11-24 09:41:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-24 09:41:57 +0100 |
commit | f1a43e3cf98d4ee5728448a4cff9675fade2e88e (patch) | |
tree | 4f9fc9f1432e06d2d282e5dc23955246fe071ac8 /apps | |
parent | 75eb325d7513ac1a3b1ba56a65167fbe6c3fe3d0 (diff) | |
parent | 00c17b2df10ecd991b1a5c721b40d41014f67787 (diff) | |
download | nextcloud-server-f1a43e3cf98d4ee5728448a4cff9675fade2e88e.tar.gz nextcloud-server-f1a43e3cf98d4ee5728448a4cff9675fade2e88e.zip |
Merge pull request #35351 from nextcloud/backport/35327/stable24
[stable24] Handle badly named version files more gracefully and log information
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_versions/lib/Storage.php | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index e314eddb945..024e1debc92 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -176,7 +176,6 @@ class Storage { * store a new version of a file. */ public static function store($filename) { - // if the file gets streamed we need to remove the .part extension // to get the right target $ext = pathinfo($filename, PATHINFO_EXTENSION); @@ -357,7 +356,6 @@ class Storage { * @return bool */ public static function rollback(string $file, int $revision, IUser $user) { - // add expected leading slash $filename = '/' . ltrim($file, '/'); @@ -495,11 +493,21 @@ class Storage { $filename = $pathparts['filename']; if ($filename === $versionedFile) { $pathparts = pathinfo($entryName); - $timestamp = substr($pathparts['extension'], 1); + $timestamp = substr($pathparts['extension'] ?? '', 1); + if (!is_numeric($timestamp)) { + \OC::$server->get(LoggerInterface::class)->error( + 'Version file {path} has incorrect name format', + [ + 'path' => $entryName, + 'app' => 'files_versions', + ] + ); + continue; + } $filename = $pathparts['filename']; $key = $timestamp . '#' . $filename; $versions[$key]['version'] = $timestamp; - $versions[$key]['humanReadableTimestamp'] = self::getHumanReadableTimestamp($timestamp); + $versions[$key]['humanReadableTimestamp'] = self::getHumanReadableTimestamp((int)$timestamp); if (empty($userFullPath)) { $versions[$key]['preview'] = ''; } else { @@ -578,7 +586,7 @@ class Storage { * @param int $timestamp * @return string for example "5 days ago" */ - private static function getHumanReadableTimestamp($timestamp) { + private static function getHumanReadableTimestamp(int $timestamp): string { $diff = time() - $timestamp; if ($diff < 60) { // first minute |