From 7810a8ca4f8555bbdaeaca02b14ca8ceff84b230 Mon Sep 17 00:00:00 2001 From: Quratulain-bilal Date: Fri, 31 Jul 2026 17:07:25 +0500 Subject: [PATCH] fix: use incremental hashing in CatalogDescriptor.get_hash() to avoid loading entire file into memory CatalogDescriptor.get_hash() called fh.read() which loads the entire file into memory before hashing. Use incremental hashlib.sha256().update() with 64 KiB chunks to prevent unbounded memory allocation on large catalog descriptor files. --- src/specify_cli/integrations/catalog.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/specify_cli/integrations/catalog.py b/src/specify_cli/integrations/catalog.py index 1794caad83..49d2545d91 100644 --- a/src/specify_cli/integrations/catalog.py +++ b/src/specify_cli/integrations/catalog.py @@ -841,5 +841,8 @@ def tools(self) -> List[Dict[str, Any]]: def get_hash(self) -> str: """SHA-256 hash of the descriptor file.""" + h = hashlib.sha256() with open(self.path, "rb") as fh: - return f"sha256:{hashlib.sha256(fh.read()).hexdigest()}" + for chunk in iter(lambda: fh.read(65536), b""): + h.update(chunk) + return f"sha256:{h.hexdigest()}"