Commit 4b10b95aac4b5ddaf4460fabdb249195bfcb625b

Authored by Christian Herdtweck
1 parent 52af4559

xls_parser: close XlsFile after use

Showing 1 changed file with 8 additions and 2 deletions
oletools/xls_parser.py
@@ -88,12 +88,18 @@ def is_xls(filename): @@ -88,12 +88,18 @@ def is_xls(filename):
88 substream. 88 substream.
89 See also: oleid.OleID.check_excel 89 See also: oleid.OleID.check_excel
90 """ 90 """
  91 + xls_file = None
91 try: 92 try:
92 - for stream in XlsFile(filename).iter_streams(): 93 + xls_file = XlsFile(filename)
  94 + for stream in xls_file.iter_streams():
93 if isinstance(stream, WorkbookStream): 95 if isinstance(stream, WorkbookStream):
94 return True 96 return True
95 except Exception: 97 except Exception:
96 - pass 98 + logging.debug('Ignoring exception in is_xls, assume is not xls',
  99 + exc_info=True)
  100 + finally:
  101 + if xls_file is not None:
  102 + xls_file.close()
97 return False 103 return False
98 104
99 105