Skip to content

Commit e86520a

Browse files
author
Jussi Kukkonen
committed
Updater: Avoid reading whole target file in memory
We don't want to read the whole file in memory as it can be huge. Use digest_fileobject() instead: This way Securesystemslib will read the file in chunks. Securesystemslib already takes care of seeking to beginning of file. Fixes #1215 Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
1 parent 9d3ef85 commit e86520a

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

tuf/client/updater.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,12 +1196,8 @@ def _check_hashes(self, file_object, trusted_hashes):
11961196
# Verify each trusted hash of 'trusted_hashes'. If all are valid, simply
11971197
# return.
11981198
for algorithm, trusted_hash in six.iteritems(trusted_hashes):
1199-
digest_object = securesystemslib.hash.digest(algorithm)
1200-
# Ensure we read from the beginning of the file object
1201-
# TODO: should we store file position (before the loop) and reset after we
1202-
# seek about?
1203-
file_object.seek(0)
1204-
digest_object.update(file_object.read())
1199+
digest_object = securesystemslib.hash.digest_fileobject(file_object,
1200+
algorithm)
12051201
computed_hash = digest_object.hexdigest()
12061202

12071203
# Raise an exception if any of the hashes are incorrect.

0 commit comments

Comments
 (0)