Skip to content

Commit

Permalink
Merge pull request #7884 from ThomasWaldmann/fix-transfer-zlib-legacy
Browse files Browse the repository at this point in the history
zlib legacy decompress fixes (master)
  • Loading branch information
ThomasWaldmann committed Oct 24, 2023
2 parents e1c75e8 + f0e9999 commit d25cc1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/borg/compress.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/borg/testsuite/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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


Expand Down

0 comments on commit d25cc1b

Please sign in to comment.