Commit a2be569f150ab3f3ab62323e89833fbe2c206dd9

Authored by Christian Herdtweck
1 parent acb05d3e

msodde: ensure XlsFile is always closed

Showing 1 changed file with 16 additions and 10 deletions
oletools/msodde.py
... ... @@ -493,17 +493,23 @@ def process_xls(filepath):
493 493 """ find dde links in excel ole file """
494 494  
495 495 result = []
496   - for stream in xls_parser.XlsFile(filepath).iter_streams():
497   - if not isinstance(stream, xls_parser.WorkbookStream):
498   - continue
499   - for record in stream.iter_records():
500   - if not isinstance(record, xls_parser.XlsRecordSupBook):
  496 + xls_file = None
  497 + try:
  498 + xls_file = xls_parser.XlsFile(filepath)
  499 + for stream in xls_file.iter_streams():
  500 + if not isinstance(stream, xls_parser.WorkbookStream):
501 501 continue
502   - if record.support_link_type in (
503   - xls_parser.XlsRecordSupBook.LINK_TYPE_OLE_DDE,
504   - xls_parser.XlsRecordSupBook.LINK_TYPE_EXTERNAL):
505   - result.append(record.virt_path.replace(u'\u0003', u' '))
506   - return u'\n'.join(result)
  502 + for record in stream.iter_records():
  503 + if not isinstance(record, xls_parser.XlsRecordSupBook):
  504 + continue
  505 + if record.support_link_type in (
  506 + xls_parser.XlsRecordSupBook.LINK_TYPE_OLE_DDE,
  507 + xls_parser.XlsRecordSupBook.LINK_TYPE_EXTERNAL):
  508 + result.append(record.virt_path.replace(u'\u0003', u' '))
  509 + return u'\n'.join(result)
  510 + finally:
  511 + if xls_file is not None:
  512 + xls_file.close()
507 513  
508 514  
509 515 def process_docx(filepath, field_filter_mode=None):
... ...