From 18090ab9355592b623200b9e3317e1a699d6909b Mon Sep 17 00:00:00 2001 From: Andrea Lazzarotto Date: Wed, 29 May 2019 16:46:22 +0200 Subject: [PATCH] Correct exception handling. Fixes #50 --- recuperabit/fs/ntfs.py | 6 ++---- recuperabit/utils.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/recuperabit/fs/ntfs.py b/recuperabit/fs/ntfs.py index e817993..f093c74 100644 --- a/recuperabit/fs/ntfs.py +++ b/recuperabit/fs/ntfs.py @@ -174,10 +174,8 @@ def parse_indx_record(entry): entry[offset + 16:], attr_types_fmt['$FILE_NAME'] ) - except UnicodeDecodeError: # Invalid file name - pass - except TypeError: # Invalid name length - pass + except (UnicodeDecodeError, TypeError): # Invalid file name or invalid name length + break # Perform checks to avoid false positives name_ok = file_name['name'] is not None namespace_ok = 0 <= file_name['namespace'] <= 3 diff --git a/recuperabit/utils.py b/recuperabit/utils.py index 8fd3a1d..e319bf9 100644 --- a/recuperabit/utils.py +++ b/recuperabit/utils.py @@ -46,7 +46,7 @@ def sectors(image, offset, size, bsize=sector_size, fill=True): if read: try: dump = image.read(size * bsize) - except IOError, MemoryError: + except (IOError, MemoryError): logging.warning( "Cannot read sector(s). Filling with 0x00. Offset: {} Size: " "{} Bsize: {}".format(offset, size, bsize)