From 5988d7951b85f2e447f748546ea37e2cb13b2664 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 26 Apr 2019 16:25:04 +0200 Subject: [PATCH] crypto: Do not throw from is_encrypted --- oletools/crypto.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/oletools/crypto.py b/oletools/crypto.py index 0164ada..57b6a6f 100644 --- a/oletools/crypto.py +++ b/oletools/crypto.py @@ -229,12 +229,18 @@ def is_encrypted(some_file): log.warning('Ignoring error during clean up: {}'.format(exc)) # if that failed, try ourselves with older and less accurate code - if isinstance(some_file, OleFileIO): - return _is_encrypted_ole(some_file) - if zipfile.is_zipfile(some_file): - return _is_encrypted_zip(some_file) - # otherwise assume it is the name of an ole file - return _is_encrypted_ole(OleFileIO(some_file)) + try: + if isinstance(some_file, OleFileIO): + return _is_encrypted_ole(some_file) + if zipfile.is_zipfile(some_file): + return _is_encrypted_zip(some_file) + # otherwise assume it is the name of an ole file + return _is_encrypted_ole(OleFileIO(some_file)) + except Exception as exc: + log.warning('Failed to check {} for encryption ({}); assume it is not ' + 'encrypted.'.format(some_file, exc)) + + return False def _is_encrypted_zip(filename): -- libgit2 0.21.4