mirror of https://github.com/borgbackup/borg.git
Merge pull request #7884 from ThomasWaldmann/fix-transfer-zlib-legacy
zlib legacy decompress fixes (master)
This commit is contained in:
commit
d25cc1b0d1
|
@ -438,8 +438,16 @@ class ZLIB_legacy(CompressorBase):
|
|||
|
||||
def decompress(self, meta, data):
|
||||
# note: for compatibility no super call, do not strip ID bytes
|
||||
assert self.legacy_mode # only borg 1.x repos have the legacy ZLIB format
|
||||
assert meta is None
|
||||
meta = {}
|
||||
meta["ctype"] = ZLIB.ID # change to non-legacy ZLIB id
|
||||
meta["clevel"] = 255 # we do not know the compression level
|
||||
meta["csize"] = len(data)
|
||||
try:
|
||||
return meta, zlib.decompress(data)
|
||||
data = zlib.decompress(data)
|
||||
self.check_fix_size(meta, data)
|
||||
return meta, data
|
||||
except zlib.error as e:
|
||||
raise DecompressionError(str(e)) from None
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ def test_lz4_buffer_allocation(monkeypatch):
|
|||
@pytest.mark.parametrize("invalid_cdata", [b"\xff\xfftotalcrap", b"\x08\x00notreallyzlib"])
|
||||
def test_autodetect_invalid(invalid_cdata):
|
||||
with pytest.raises(ValueError):
|
||||
Compressor(**params, legacy_mode=True).decompress({}, invalid_cdata)
|
||||
Compressor(**params, legacy_mode=True).decompress(None, invalid_cdata)
|
||||
|
||||
|
||||
def test_zlib_legacy_compat():
|
||||
|
@ -61,7 +61,7 @@ def test_zlib_legacy_compat():
|
|||
meta1, cdata1 = c.compress({}, DATA)
|
||||
cdata2 = zlib.compress(DATA, level)
|
||||
assert cdata1 == cdata2
|
||||
meta2, data2 = c.decompress({}, cdata2)
|
||||
meta2, data2 = c.decompress(None, cdata2)
|
||||
assert DATA == data2
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue