Merge pull request #7884 from ThomasWaldmann/fix-transfer-zlib-legacy

zlib legacy decompress fixes (master)
This commit is contained in:
TW 2023-10-25 00:07:21 +02:00 committed by GitHub
commit d25cc1b0d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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