From 2aec83f057f7437c17dfb5493183712e44456e9d Mon Sep 17 00:00:00 2001 From: Paul Culley Date: Mon, 3 Sep 2018 19:41:27 -0500 Subject: [PATCH] Fix generate_checksum routine to avoid MemoryError crash (#649) with very large files and 32-bit OS Issue #10690 --- gramps/gen/utils/file.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gramps/gen/utils/file.py b/gramps/gen/utils/file.py index 02bcb5c5e..531071d03 100644 --- a/gramps/gen/utils/file.py +++ b/gramps/gen/utils/file.py @@ -251,11 +251,17 @@ def create_checksum(full_path): Create a md5 hash for the given file. """ full_path = os.path.normpath(full_path) + md5 = hashlib.md5() try: with open(full_path, 'rb') as media_file: - md5sum = hashlib.md5(media_file.read()).hexdigest() + while True: + buf = media_file.read(65536) + if not buf: + break + md5.update(buf) + md5sum = md5.hexdigest() except IOError: - md5sum = '' + md5sum = '' except UnicodeEncodeError: - md5sum = '' + md5sum = '' return md5sum