diff --git a/biostools/extractors.py b/biostools/extractors.py index 742f484..77efc15 100644 --- a/biostools/extractors.py +++ b/biostools/extractors.py @@ -293,7 +293,11 @@ class ASTExtractor(Extractor): def extract(self, file_path, file_header, dest_dir, dest_dir_0): # Stop if this file is too small. - if os.path.getsize(file_path) <= 0x9083: + try: + file_size = os.path.getsize(file_path) + except: + return False + if file_size <= 0x9083: return False # Look for the AST signatures. @@ -305,48 +309,51 @@ class ASTExtractor(Extractor): return True # Open AST image. - with open(file_path, 'rb') as in_f: - # Skip the initial 72 sectors. - in_f.seek(0x9000) + try: + with open(file_path, 'rb') as in_f: + # Skip the initial 72 sectors. + in_f.seek(0x9000) - # Copy payload. - header = b'' - dest_file_path = os.path.join(dest_dir, 'ast.bin') - try: - with open(dest_file_path, 'wb') as out_f: - data = remaining = True - while data and remaining > 0: - payload_size = 15 * 512 - if data == True: - # Check the header on the first payload sector. - header += in_f.read(0x83) - if not self._ast_payload_pattern.match(header[:0x10]): - raise Exception('missing header') - - # Subtract header from payload. - remaining, = struct.unpack(' 0: + payload_size = 15 * 512 + if data == True: + # Check the header on the first payload sector. + header += in_f.read(0x83) + if not self._ast_payload_pattern.match(header[:0x10]): + raise Exception('missing header') + + # Subtract header from payload. + remaining, = struct.unpack('= 8 + (width * height): + try: + file_size = os.path.getsize(file_path) + except: + file_size = len(file_header) + if file_size >= 8 + (width * height): func = self._convert_epav2_8b else: func = self._convert_epav2_4b @@ -941,7 +952,10 @@ class ImageExtractor(Extractor): paletted = file_header[3] != 0 payload_size = math.ceil((width * height) / 2) if paletted: - file_size = os.path.getsize(file_path) + try: + file_size = os.path.getsize(file_path) + except: + file_size = len(file_header) if file_size > 18 + payload_size: palette_size, = struct.unpack(' file_size: return False