Skip to content

Commit

Permalink
fix(files): Catch null possibilities before hash
Browse files Browse the repository at this point in the history
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

fix: don't use OCP

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
  • Loading branch information
solracsf committed Jul 29, 2024
1 parent 13d2b67 commit 7da44b6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,25 @@ 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|bool {
$sourcePath = $this->getSourcePath($path);
if ($sourcePath === null) {
\OC::$server->get(LoggerInterface::class)->error('Source path returned null for path: ' . $sourcePath, ['app' => 'core']);
return false;
}

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) {
Expand Down

0 comments on commit 7da44b6

Please sign in to comment.