From 2608766ed9e844ea563c6a64dced3bdaf5fba395 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Mon, 1 Jul 2024 16:52:23 +0200 Subject: [PATCH] fix(files): Ensure that the hash method does not return null To match https://github.com/nextcloud/server/blob/beececf66068f57c416225efcde9b44ce5c2e835/lib/private/Files/View.php#L1050 - Fix https://github.com/nextcloud/server/issues/44110 Signed-off-by: Louis Chemineau --- lib/private/Files/Storage/Local.php | 11 +++++++++-- lib/private/Files/Storage/Wrapper/Availability.php | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index a23879607c2df..3c241dbc4bc3b 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -439,8 +439,15 @@ public function fopen($path, $mode) { return $result; } - public function hash($type, $path, $raw = false) { - return hash_file($type, $this->getSourcePath($path), $raw); + public function hash($type, $path, $raw = false): string|false { + /** @var string|false|null */ + $hash = hash_file($type, $this->getSourcePath($path), $raw); + + if ($hash === null) { + return false; + } + + return $hash; } public function free_space($path) { diff --git a/lib/private/Files/Storage/Wrapper/Availability.php b/lib/private/Files/Storage/Wrapper/Availability.php index 693d943f0dc28..bab43977b608f 100644 --- a/lib/private/Files/Storage/Wrapper/Availability.php +++ b/lib/private/Files/Storage/Wrapper/Availability.php @@ -334,6 +334,7 @@ public function hash($type, $path, $raw = false) { return parent::hash($type, $path, $raw); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } }