allow for detecting overlapping objects with tarfile
[python-delta-tar] / deltatar / tarfile.py
index c63bb23..31e46b9 100644 (file)
@@ -1026,7 +1026,14 @@ class _Stream:
                                 t.append (buf)
                             if len (t) > 0:
                                 break
-                            raise
+                        raise
+                    except ReadError: # gzip troubles
+                        if self.tolerance == TOLERANCE_RESCUE:
+                            if len (buf) > 0:
+                                t.append (buf)
+                            if len (t) > 0:
+                                break
+                        raise
                     except EndOfFile:
                         # happens at the end of the file
                         pass
@@ -1082,13 +1089,21 @@ class _Stream:
                 if self.tolerance == TOLERANCE_STRICT:
                     raise
                 self.encryption.drop ()
-                if good_crypto == 0:
-                    raise
-                # this may occur at any of the three crypto operations above.
-                # some objects did validate; discard all data after it; next
-                # call will start with the bad object and error out immediately
-                self.buf = b"".join (t [good_crypto:])
-                return b"".join (t [:good_crypto])
+                if self.tolerance == TOLERANCE_RECOVER:
+                    if good_crypto == 0:
+                        raise
+                    # this may occur at any of the three crypto operations above.
+                    # some objects did validate; discard all data after it; next
+                    # call will start with the bad object and error out immediately
+                    self.buf = b"".join (t [good_crypto:])
+                    return b"".join (t [:good_crypto])
+                elif self.tolerance == TOLERANCE_RESCUE:
+                    # keep what we have so far despite the finalization issue
+                    t.append (buf)
+                    c += len (buf)
+                    break
+                else:
+                    raise RuntimeError("internal error: bad tolerance level")
 
             if not buf: ## XXX stream terminated prematurely; this should be an error
                 break