Skip to content

Commit 5727edc

Browse files
committed
fix(files): Catch null possibilities before hash
Signed-off-by: Git'Fellow <[email protected]> fix: don't use OCP Signed-off-by: Git'Fellow <[email protected]> fix: Also check if null Signed-off-by: Git'Fellow <[email protected]>
1 parent 13d2b67 commit 5727edc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/private/Files/Storage/Local.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,20 @@ public function fopen($path, $mode) {
400400
return $result;
401401
}
402402

403-
public function hash($type, $path, $raw = false) {
404-
return hash_file($type, $this->getSourcePath($path), $raw);
403+
public function hash($type, $path, $raw = false): string|bool {
404+
$sourcePath = $this->getSourcePath($path);
405+
if ($sourcePath === null || !file_exists($sourcePath) || !is_readable($sourcePath)) {
406+
\OC::$server->get(LoggerInterface::class)->error('Source path does not exist or is not readable: ' . $sourcePath, ['app' => 'core']);
407+
return false;
408+
}
409+
410+
$validAlgorithms = hash_algos();
411+
if (!in_array($type, $validAlgorithms)) {
412+
\OC::$server->get(LoggerInterface::class)->error('Invalid hash algorithm: ' . $type, ['app' => 'core']);
413+
return false;
414+
}
415+
416+
return hash_file($type, $sourcePath, $raw);
405417
}
406418

407419
public function free_space($path) {

0 commit comments

Comments
 (0)