Skip to content

Commit

Permalink
Issue #634: Explicitly check if path is directory
Browse files Browse the repository at this point in the history
  • Loading branch information
petersistrom committed Sep 18, 2024
1 parent 59df022 commit 9819757
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions classes/local/store/object_file_system.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ public function is_file_readable_externally_by_storedfile(stored_file $file) {
* @return bool
*/
public function is_file_readable_externally_by_hash($contenthash) {
if ($contenthash === sha1('')) {
// Files with empty size are either directories or empty.
$path = $this->get_external_path_from_hash($contenthash, false);

if ($contenthash === sha1('') && is_dir($path)) {
// Explicitly check if it is a directory, handle empty files as normal.
// We handle these virtually.
return true;
}

$path = $this->get_external_path_from_hash($contenthash, false);

// Note - it is not possible to perform a content recovery safely from a hash alone.
return is_readable($path);
}
Expand Down

0 comments on commit 9819757

Please sign in to comment.