From af520d265dd78f525e5cf7ba39f63b940d4d4da3 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 15 Apr 2023 19:03:11 +0100 Subject: [PATCH] add invalid hash check --- upload.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/upload.php b/upload.php index bb5010e..93349b8 100644 --- a/upload.php +++ b/upload.php @@ -47,14 +47,20 @@ if (!isZipFile($map["name"])) { die(); } -$fileHash = hash_file("sha256", $file); // the hash of the file +$fileHash = null; +try { + $fileHash = hash_file("sha256", $file); // the hash of the file +} catch (Exception $e) { +} $exists = false; -foreach (scandir($target_dir) as $file) { // scan the maps directory for a file with the same hash - if (hash_file("sha256", $target_dir . $file) == $fileHash) { - $mapId = pathinfo($file, PATHINFO_FILENAME); - $exists = true; - break; +if ($fileHash != null) { + foreach (scandir($target_dir) as $file) { // scan the maps directory for a file with the same hash + if (hash_file("sha256", $target_dir . $file) == $fileHash) { + $mapId = pathinfo($file, PATHINFO_FILENAME); + $exists = true; + break; + } } }