diff --git a/oletools/msodde.py b/oletools/msodde.py index 4a0ca78..9f16eb9 100644 --- a/oletools/msodde.py +++ b/oletools/msodde.py @@ -533,17 +533,16 @@ def process_xls(filepath): def process_docx(filepath, field_filter_mode=None): log.debug('process_docx') all_fields = [] - z = zipfile.ZipFile(filepath) - for filepath in z.namelist(): - if filepath in LOCATIONS: - data = z.read(filepath) - fields = process_xml(data) - if len(fields) > 0: - #print ('DDE Links in %s:'%filepath) - #for f in fields: - # print(f) - all_fields.extend(fields) - z.close() + with zipfile.ZipFile(filepath) as z: + for filepath in z.namelist(): + if filepath in LOCATIONS: + data = z.read(filepath) + fields = process_xml(data) + if len(fields) > 0: + #print ('DDE Links in %s:'%filepath) + #for f in fields: + # print(f) + all_fields.extend(fields) # apply field command filter log.debug('filtering with mode "{0}"'.format(field_filter_mode)) diff --git a/oletools/ooxml.py b/oletools/ooxml.py index 133a671..3de095c 100644 --- a/oletools/ooxml.py +++ b/oletools/ooxml.py @@ -337,7 +337,8 @@ class XmlParser(object): yields 3-tuples (filename, content_type, file_handle) where content_type is based on filename or default for extension or is None, - and file_handle is a ZipSubFile + and file_handle is a ZipSubFile. Caller does not have to care about + closing handle, will be closed even in error condition. To handle binary parts of an xlsb file, use xls_parser.parse_xlsb_part """