From 989ead6cf6d848794a51bc63a4acd8e5ea4373fa Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 8 Dec 2017 14:48:12 +0100 Subject: [PATCH] xls_parser: close stream after xlsb-parsing; update stream constructor --- oletools/xls_parser.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/oletools/xls_parser.py b/oletools/xls_parser.py index e0b177e..06ee90d 100644 --- a/oletools/xls_parser.py +++ b/oletools/xls_parser.py @@ -55,7 +55,8 @@ import sys import os.path from struct import unpack import logging -from record_base import OleRecordFile, OleRecordStream, OleRecordBase, test +from record_base import OleRecordFile, OleRecordStream, OleRecordBase, test, \ + STGTY_STREAM # === PYTHON 2+3 SUPPORT ====================================================== @@ -452,10 +453,19 @@ class XlsbBeginSupBook(XlsbRecord): ############################################################################### -def parse_xlsb_part(stream, _, filename): - """ Excel xlsb files also have a record structure. iter records """ - for record in XlsbStream(stream, filename).iter_records(): - yield record +def parse_xlsb_part(file_stream, _, filename): + """ Excel xlsb files also have bin files with record structure. iter! """ + xlsb_stream = None + try: + xlsb_stream = XlsbStream(file_stream, file_stream.size, filename, + STGTY_STREAM) + for record in xlsb_stream.iter_records(): + yield record + except Exception: + raise + finally: + if xlsb_stream is not None: + xlsb_stream.close() ############################################################################### -- libgit2 0.21.4