From 4f6c9c5a9a38144726d484a506342ecfaa319b5f Mon Sep 17 00:00:00 2001 From: Peter Sistrom Date: Wed, 18 Sep 2024 11:53:05 +1000 Subject: [PATCH] Issue #634: Explicitly check if path is directory --- classes/local/store/object_file_system.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/local/store/object_file_system.php b/classes/local/store/object_file_system.php index de30f1d2..de53f1a4 100644 --- a/classes/local/store/object_file_system.php +++ b/classes/local/store/object_file_system.php @@ -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); }