Commit f1e5ebe7a14ea845660ce6a6d6b37fac3b3a1f56
1 parent
d604e72d
simplify exception-handling around mso_file_extract in open_mht and open_word2003xml
Showing
1 changed file
with
14 additions
and
10 deletions
oletools/olevba.py
| @@ -2094,11 +2094,14 @@ class VBA_Parser(object): | @@ -2094,11 +2094,14 @@ class VBA_Parser(object): | ||
| 2094 | if is_mso_file(mso_data): | 2094 | if is_mso_file(mso_data): |
| 2095 | # decompress the zlib data stored in the MSO file, which is the OLE container: | 2095 | # decompress the zlib data stored in the MSO file, which is the OLE container: |
| 2096 | # TODO: handle different offsets => separate function | 2096 | # TODO: handle different offsets => separate function |
| 2097 | - ole_data = mso_file_extract(mso_data) | ||
| 2098 | try: | 2097 | try: |
| 2098 | + ole_data = mso_file_extract(mso_data) | ||
| 2099 | self.ole_subfiles.append(VBA_Parser(filename=fname, data=ole_data)) | 2099 | self.ole_subfiles.append(VBA_Parser(filename=fname, data=ole_data)) |
| 2100 | - except Exception: | ||
| 2101 | - log.error('%s does not contain a valid OLE file' % fname) | 2100 | + except MsoExtractionError: |
| 2101 | + log.exception('Failed decompressing an MSO container in %r - %s' | ||
| 2102 | + % (fname, MSG_OLEVBA_ISSUES)) | ||
| 2103 | + except FileOpenError as exc: | ||
| 2104 | + log.debug('%s is not a valid OLE sub file (%s)' % (fname, exc)) | ||
| 2102 | else: | 2105 | else: |
| 2103 | log.error('%s is not a valid MSO file' % fname) | 2106 | log.error('%s is not a valid MSO file' % fname) |
| 2104 | # set type only if parsing succeeds | 2107 | # set type only if parsing succeeds |
| @@ -2150,16 +2153,17 @@ class VBA_Parser(object): | @@ -2150,16 +2153,17 @@ class VBA_Parser(object): | ||
| 2150 | log.debug('Found ActiveMime header, decompressing MSO container') | 2153 | log.debug('Found ActiveMime header, decompressing MSO container') |
| 2151 | try: | 2154 | try: |
| 2152 | ole_data = mso_file_extract(part_data) | 2155 | ole_data = mso_file_extract(part_data) |
| 2153 | - try: | ||
| 2154 | - # TODO: check if it is actually an OLE file | ||
| 2155 | - # TODO: get the MSO filename from content_location? | ||
| 2156 | - self.ole_subfiles.append(VBA_Parser(filename=fname, data=ole_data)) | ||
| 2157 | - except Exception: | ||
| 2158 | - log.debug('%s does not contain a valid OLE file' % fname) | ||
| 2159 | - except Exception: | 2156 | + |
| 2157 | + # TODO: check if it is actually an OLE file | ||
| 2158 | + # TODO: get the MSO filename from content_location? | ||
| 2159 | + self.ole_subfiles.append(VBA_Parser(filename=fname, data=ole_data)) | ||
| 2160 | + except MsoExtractionError: | ||
| 2160 | log.exception('Failed decompressing an MSO container in %r - %s' | 2161 | log.exception('Failed decompressing an MSO container in %r - %s' |
| 2161 | % (fname, MSG_OLEVBA_ISSUES)) | 2162 | % (fname, MSG_OLEVBA_ISSUES)) |
| 2162 | # TODO: bug here - need to split in smaller functions/classes? | 2163 | # TODO: bug here - need to split in smaller functions/classes? |
| 2164 | + except FileOpenError as exc: | ||
| 2165 | + log.debug('%s does not contain a valid OLE file (%s)' | ||
| 2166 | + % (fname, exc)) | ||
| 2163 | else: | 2167 | else: |
| 2164 | try: | 2168 | try: |
| 2165 | log.debug('type(part_data) = %s' % type(part_data)) | 2169 | log.debug('type(part_data) = %s' % type(part_data)) |