mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 17:57:59 +00:00
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:
parent
46ba9352fc
commit
503e9a27e6
3 changed files with 17 additions and 7 deletions
|
@ -4,9 +4,9 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
lzma = None
|
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":
|
cdef extern from "lz4.h":
|
||||||
int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) nogil
|
int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) nogil
|
||||||
|
@ -112,7 +112,7 @@ class LZ4(CompressorBase):
|
||||||
break
|
break
|
||||||
if osize > 2 ** 30:
|
if osize > 2 ** 30:
|
||||||
# this is insane, get out of here
|
# 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:
|
# likely the buffer was too small, get a bigger one:
|
||||||
osize = int(1.5 * osize)
|
osize = int(1.5 * osize)
|
||||||
return dest[:rsize]
|
return dest[:rsize]
|
||||||
|
@ -138,7 +138,10 @@ class LZMA(CompressorBase):
|
||||||
|
|
||||||
def decompress(self, data):
|
def decompress(self, data):
|
||||||
data = super().decompress(data)
|
data = super().decompress(data)
|
||||||
|
try:
|
||||||
return lzma.decompress(data)
|
return lzma.decompress(data)
|
||||||
|
except lzma.LZMAError as e:
|
||||||
|
raise DecompressionError(str(e)) from None
|
||||||
|
|
||||||
|
|
||||||
class ZLIB(CompressorBase):
|
class ZLIB(CompressorBase):
|
||||||
|
@ -167,7 +170,10 @@ class ZLIB(CompressorBase):
|
||||||
|
|
||||||
def decompress(self, data):
|
def decompress(self, data):
|
||||||
# note: for compatibility no super call, do not strip ID bytes
|
# note: for compatibility no super call, do not strip ID bytes
|
||||||
|
try:
|
||||||
return zlib.decompress(data)
|
return zlib.decompress(data)
|
||||||
|
except zlib.error as e:
|
||||||
|
raise DecompressionError(str(e)) from None
|
||||||
|
|
||||||
|
|
||||||
COMPRESSOR_TABLE = {
|
COMPRESSOR_TABLE = {
|
||||||
|
|
|
@ -81,6 +81,10 @@ class IntegrityError(ErrorWithTraceback):
|
||||||
"""Data integrity error: {}"""
|
"""Data integrity error: {}"""
|
||||||
|
|
||||||
|
|
||||||
|
class DecompressionError(IntegrityError):
|
||||||
|
"""Decompression error: {}"""
|
||||||
|
|
||||||
|
|
||||||
class ExtensionModuleError(Error):
|
class ExtensionModuleError(Error):
|
||||||
"""The Borg binary extension modules do not seem to be properly installed"""
|
"""The Borg binary extension modules do not seem to be properly installed"""
|
||||||
|
|
||||||
|
@ -99,7 +103,7 @@ def check_extension_modules():
|
||||||
raise ExtensionModuleError
|
raise ExtensionModuleError
|
||||||
if chunker.API_VERSION != '1.1_01':
|
if chunker.API_VERSION != '1.1_01':
|
||||||
raise ExtensionModuleError
|
raise ExtensionModuleError
|
||||||
if compress.API_VERSION != '1.1_01':
|
if compress.API_VERSION != '1.1_02':
|
||||||
raise ExtensionModuleError
|
raise ExtensionModuleError
|
||||||
if crypto.API_VERSION != '1.1_01':
|
if crypto.API_VERSION != '1.1_01':
|
||||||
raise ExtensionModuleError
|
raise ExtensionModuleError
|
||||||
|
|
|
@ -265,7 +265,7 @@ def cmd(self, *args, **kw):
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def create_src_archive(self, name):
|
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):
|
def open_archive(self, name):
|
||||||
repository = Repository(self.repository_path, exclusive=True)
|
repository = Repository(self.repository_path, exclusive=True)
|
||||||
|
|
Loading…
Reference in a new issue