Fix compression exceptions (#2224)

* trigger bug in --verify-data, see #2221

* raise decompression errors as DecompressionError, fixes #2221

this is a subclass of IntegrityError, so borg check --verify-data works correctly if
the decompressor stumbles over corrupted data before the plaintext gets verified
(in a unencrypted repository, otherwise the MAC check would fail first).

* fixup: fix exception docstring, add placeholder, change wording
This commit is contained in:
TW 2017-03-04 00:01:02 +01:00 committed by enkore
parent 46ba9352fc
commit 503e9a27e6
3 changed files with 17 additions and 7 deletions

View File

@ -4,9 +4,9 @@ try:
except ImportError:
lzma = None
from .helpers import Buffer
from .helpers import Buffer, DecompressionError
API_VERSION = '1.1_01'
API_VERSION = '1.1_02'
cdef extern from "lz4.h":
int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) nogil
@ -112,7 +112,7 @@ class LZ4(CompressorBase):
break
if osize > 2 ** 30:
# this is insane, get out of here
raise Exception('lz4 decompress failed')
raise DecompressionError('lz4 decompress failed')
# likely the buffer was too small, get a bigger one:
osize = int(1.5 * osize)
return dest[:rsize]
@ -138,7 +138,10 @@ class LZMA(CompressorBase):
def decompress(self, data):
data = super().decompress(data)
return lzma.decompress(data)
try:
return lzma.decompress(data)
except lzma.LZMAError as e:
raise DecompressionError(str(e)) from None
class ZLIB(CompressorBase):
@ -167,7 +170,10 @@ class ZLIB(CompressorBase):
def decompress(self, data):
# note: for compatibility no super call, do not strip ID bytes
return zlib.decompress(data)
try:
return zlib.decompress(data)
except zlib.error as e:
raise DecompressionError(str(e)) from None
COMPRESSOR_TABLE = {

View File

@ -81,6 +81,10 @@ class IntegrityError(ErrorWithTraceback):
"""Data integrity error: {}"""
class DecompressionError(IntegrityError):
"""Decompression error: {}"""
class ExtensionModuleError(Error):
"""The Borg binary extension modules do not seem to be properly installed"""
@ -99,7 +103,7 @@ def check_extension_modules():
raise ExtensionModuleError
if chunker.API_VERSION != '1.1_01':
raise ExtensionModuleError
if compress.API_VERSION != '1.1_01':
if compress.API_VERSION != '1.1_02':
raise ExtensionModuleError
if crypto.API_VERSION != '1.1_01':
raise ExtensionModuleError

View File

@ -265,7 +265,7 @@ class ArchiverTestCaseBase(BaseTestCase):
return output
def create_src_archive(self, name):
self.cmd('create', '--compression=none', self.repository_location + '::' + name, src_dir)
self.cmd('create', '--compression=lz4', self.repository_location + '::' + name, src_dir)
def open_archive(self, name):
repository = Repository(self.repository_path, exclusive=True)