Skip to content

Commit d25cc1b

Browse files
Merge pull request #7884 from ThomasWaldmann/fix-transfer-zlib-legacy
zlib legacy decompress fixes (master)
2 parents e1c75e8 + f0e9999 commit d25cc1b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/borg/compress.pyx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,16 @@ class ZLIB_legacy(CompressorBase):
438438

439439
def decompress(self, meta, data):
440440
# note: for compatibility no super call, do not strip ID bytes
441+
assert self.legacy_mode # only borg 1.x repos have the legacy ZLIB format
442+
assert meta is None
443+
meta = {}
444+
meta["ctype"] = ZLIB.ID # change to non-legacy ZLIB id
445+
meta["clevel"] = 255 # we do not know the compression level
446+
meta["csize"] = len(data)
441447
try:
442-
return meta, zlib.decompress(data)
448+
data = zlib.decompress(data)
449+
self.check_fix_size(meta, data)
450+
return meta, data
443451
except zlib.error as e:
444452
raise DecompressionError(str(e)) from None
445453

src/borg/testsuite/compress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_lz4_buffer_allocation(monkeypatch):
5050
@pytest.mark.parametrize("invalid_cdata", [b"\xff\xfftotalcrap", b"\x08\x00notreallyzlib"])
5151
def test_autodetect_invalid(invalid_cdata):
5252
with pytest.raises(ValueError):
53-
Compressor(**params, legacy_mode=True).decompress({}, invalid_cdata)
53+
Compressor(**params, legacy_mode=True).decompress(None, invalid_cdata)
5454

5555

5656
def test_zlib_legacy_compat():
@@ -61,7 +61,7 @@ def test_zlib_legacy_compat():
6161
meta1, cdata1 = c.compress({}, DATA)
6262
cdata2 = zlib.compress(DATA, level)
6363
assert cdata1 == cdata2
64-
meta2, data2 = c.decompress({}, cdata2)
64+
meta2, data2 = c.decompress(None, cdata2)
6565
assert DATA == data2
6666

6767

0 commit comments

Comments
 (0)