From 13cb1309300930a60d9e26c54bc6a46c10c6ed49 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Fri, 18 Oct 2024 06:14:30 +0900 Subject: [PATCH] case-insensitive hash compare --- modules/util.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/util.py b/modules/util.py index 9e215d799..baeba2fa2 100644 --- a/modules/util.py +++ b/modules/util.py @@ -281,8 +281,10 @@ def load_file_from_url( def compare_sha256(file_path: str, hash_prefix: str) -> bool: """Check if the SHA256 hash of the file matches the given prefix.""" import hashlib - sha256 = hashlib.sha256() - with open(file_path, 'rb') as f: - for chunk in iter(lambda: f.read(4096), b''): - sha256.update(chunk) - return sha256.hexdigest().startswith(hash_prefix) + hash_sha256 = hashlib.sha256() + blksize = 1024 * 1024 + + with open(file_path, "rb") as f: + for chunk in iter(lambda: f.read(blksize), b""): + hash_sha256.update(chunk) + return hash_sha256.hexdigest().startswith(hash_prefix.strip().lower())