Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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]>
  • Loading branch information
solracsf committed Jul 29, 2024
commit 5727edcedc79172addf0c3b9c6f531254ebbf1cf
16 changes: 14 additions & 2 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -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|bool {
$sourcePath = $this->getSourcePath($path);
if ($sourcePath === null || !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