fix decompression error handling
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Fri, 21 Apr 2017 13:23:49 +0000 (15:23 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
This seems to be a copy&paste oversight from

    commit be60ffd0598fec172eccb69f3c6a8433af6fb643
    Author: Eduardo Robles Elvira <edulix@wadobo.com>
    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

index fe0a0aa..84a3c12 100644 (file)
@@ -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