From e7c00dc6e67e74116720d8e1cb3ae37c4f9e272b Mon Sep 17 00:00:00 2001 From: Zhenhai Zhang Date: Sat, 17 Oct 2020 18:48:34 +0800 Subject: [PATCH] Update olefile.py Fix when scan incorrect doc cause memory crash --- olefile/olefile.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/olefile/olefile.py b/olefile/olefile.py index 8348cd9..1549cee 100644 --- a/olefile/olefile.py +++ b/olefile/olefile.py @@ -618,12 +618,16 @@ def __init__(self, fp, sect, size, offset, sectorsize, fat, filesize, olefileio) log.debug('nb_sectors = %d' % nb_sectors) # This number should (at least) be less than the total number of # sectors in the given FAT: + data = [] if nb_sectors > len(fat): self.ole._raise_defect(DEFECT_INCORRECT, 'malformed OLE document, stream too large') + data = b"".join(data) + io.BytesIO.__init__(self, data) + return # optimization(?): data is first a list of strings, and join() is called # at the end to concatenate all in one string. # (this may not be really useful with recent Python versions) - data = [] + # if size is zero, then first sector index should be ENDOFCHAIN: if size == 0 and sect != ENDOFCHAIN: log.debug('size == 0 and sect != ENDOFCHAIN:')