diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index a65d60bf278dd..cc828b1371f81 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -400,8 +400,20 @@ 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 { + $sourcePath = $this->getSourcePath($path); + if (!file_exists($sourcePath) || !is_readable($sourcePath)) { + \OC::$server->get(LoggerInterface::class)->error('Source path does not exist or is not readable: ' . $sourcePath, ['app' => 'core']); + return false; + } + + $validAlgorithms = hash_algos(); + if (!in_array($type, $validAlgorithms)) { + \OC::$server->get(LoggerInterface::class)->error('Invalid hash algorithm: ' . $type, ['app' => 'core']); + return false; + } + + return hash_file($type, $sourcePath, $raw); } public function free_space($path) {