mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
format_hash() should not consume unbounded memory
This commit is contained in:
parent
8da8075ee2
commit
a94b78cfed
@ -1132,11 +1132,16 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def format_hash(self, id_, fmt):
|
def format_hash(self, id_, fmt):
|
||||||
data = self.format(id_, fmt, index_is_id=True)
|
path = self.format_abspath(id_, fmt, index_is_id=True)
|
||||||
if data is None:
|
if path is None:
|
||||||
raise NoSuchFormat('Record %d has no fmt: %s'%(id_, fmt))
|
raise NoSuchFormat('Record %d has no fmt: %s'%(id_, fmt))
|
||||||
sha = hashlib.sha256()
|
sha = hashlib.sha256()
|
||||||
sha.update(data)
|
with lopen(path, 'rb') as f:
|
||||||
|
while True:
|
||||||
|
raw = f.read(SPOOL_SIZE)
|
||||||
|
sha.update(raw)
|
||||||
|
if len(raw) < SPOOL_SIZE:
|
||||||
|
break
|
||||||
return sha.hexdigest()
|
return sha.hexdigest()
|
||||||
|
|
||||||
def format_abspath(self, index, format, index_is_id=False):
|
def format_abspath(self, index, format, index_is_id=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user