Commit e97e15a67ae2ac7bd516d83e983e4f966c0d0f19

Authored by Christian Herdtweck
1 parent 14045282

specify exceptions from open_... methods (as best as possible)

Showing 1 changed file with 4 additions and 4 deletions
oletools/olevba.py
@@ -299,7 +299,7 @@ class FileOpenError(Exception): @@ -299,7 +299,7 @@ class FileOpenError(Exception):
299 """ 299 """
300 300
301 def __init__(self, filename): 301 def __init__(self, filename):
302 - super(InvalidFileTypeError, self).__init__( 302 + super(FileOpenError, self).__init__(
303 'Failed to open file %s ... probably not supported' % filename) 303 'Failed to open file %s ... probably not supported' % filename)
304 self.filename = filename 304 self.filename = filename
305 305
@@ -1620,7 +1620,7 @@ def detect_base64_strings(vba_code): @@ -1620,7 +1620,7 @@ def detect_base64_strings(vba_code):
1620 decoded = base64.b64decode(value) 1620 decoded = base64.b64decode(value)
1621 results.append((value, decoded)) 1621 results.append((value, decoded))
1622 found.add(value) 1622 found.add(value)
1623 - except Exception: 1623 + except (TypeError, ValueError) as exc:
1624 # if an exception occurs, it is likely not a base64-encoded string 1624 # if an exception occurs, it is likely not a base64-encoded string
1625 pass 1625 pass
1626 return results 1626 return results
@@ -2016,7 +2016,7 @@ class VBA_Parser(object): @@ -2016,7 +2016,7 @@ class VBA_Parser(object):
2016 # TODO: raise TypeError if this is a Powerpoint 97 file, since VBA macros cannot be detected yet 2016 # TODO: raise TypeError if this is a Powerpoint 97 file, since VBA macros cannot be detected yet
2017 # set type only if parsing succeeds 2017 # set type only if parsing succeeds
2018 self.type = TYPE_OLE 2018 self.type = TYPE_OLE
2019 - except Exception: 2019 + except (IOError, TypeError, ValueError):
2020 # TODO: handle OLE parsing exceptions 2020 # TODO: handle OLE parsing exceptions
2021 log.exception('Failed OLE parsing for file %r' % self.filename) 2021 log.exception('Failed OLE parsing for file %r' % self.filename)
2022 pass 2022 pass
@@ -2051,7 +2051,7 @@ class VBA_Parser(object): @@ -2051,7 +2051,7 @@ class VBA_Parser(object):
2051 z.close() 2051 z.close()
2052 # set type only if parsing succeeds 2052 # set type only if parsing succeeds
2053 self.type = TYPE_OpenXML 2053 self.type = TYPE_OpenXML
2054 - except Exception: 2054 + except (RuntimeError, zipfile.BadZipfile, zipfile.LargeZipFile, IOError) as exc:
2055 # TODO: handle parsing exceptions 2055 # TODO: handle parsing exceptions
2056 log.exception('Failed Zip/OpenXML parsing for file %r' % self.filename) 2056 log.exception('Failed Zip/OpenXML parsing for file %r' % self.filename)
2057 pass 2057 pass