Skip to content

Commit 7810a8c

Browse files
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.
1 parent 5e2f9bc commit 7810a8c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/specify_cli/integrations/catalog.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,5 +841,8 @@ def tools(self) -> List[Dict[str, Any]]:
841841

842842
def get_hash(self) -> str:
843843
"""SHA-256 hash of the descriptor file."""
844+
h = hashlib.sha256()
844845
with open(self.path, "rb") as fh:
845-
return f"sha256:{hashlib.sha256(fh.read()).hexdigest()}"
846+
for chunk in iter(lambda: fh.read(65536), b""):
847+
h.update(chunk)
848+
return f"sha256:{h.hexdigest()}"

0 commit comments

Comments
 (0)