From 46c03c021f0e7f28452079d21645fc27993bcafb Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 21 Apr 2017 15:23:49 +0200 Subject: [PATCH] fix decompression error handling This seems to be a copy&paste oversight from commit be60ffd0598fec172eccb69f3c6a8433af6fb643 Author: Eduardo Robles Elvira Date: Mon Nov 4 08:50:55 2013 +0100 initial port to python 3, not finished which added the per-compression mode exceptions but not the actual handling code. --- deltatar/tarfile.py | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index fe0a0aa..84a3c12 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -447,7 +447,7 @@ class _Stream: self.concat_stream = concat_stream self.last_block_offset = 0 self.dbuf = b"" # ??? - self.exception = None + self.exception = None # communicate decompression failure self.compresslevel = compresslevel self.bytes_written = 0 # crypto parameters @@ -464,10 +464,11 @@ class _Stream: if concat_stream is False: if mode == "r": self._init_read_gz() - self.exception = zlib.error elif mode == "w": self._new_gz_block() self.crc = zlib.crc32(b"") & 0xFFFFffff + if mode == "r": + self.exception = zlib.error elif comptype == "bz2": if self.encryption is not None: @@ -861,7 +862,7 @@ class _Stream: if self.cmp is not None: try: buf = self.cmp.decompress(buf) - except OSError: + except self.exception: raise ReadError("invalid compressed data") except Exception as e: # happens at the end of the file -- 1.7.1