From 0cfdf6da911550dd52bd8861159d9b44ae026a28 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 24 Oct 2023 19:37:24 +0200 Subject: [PATCH 1/3] zlib legacy decompress: return meta dict, fixes #7883 for the other compression methods, this is done in the base class, but the zlib legacy does not call that method as it also removes the header bytes, which zlib legacy does not have. --- src/borg/compress.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/borg/compress.pyx b/src/borg/compress.pyx index e259c37484..3b6deb0d58 100644 --- a/src/borg/compress.pyx +++ b/src/borg/compress.pyx @@ -438,6 +438,12 @@ 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) except zlib.error as e: From 0ac525bb054138bb44ccaeb0ae66240202519721 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 24 Oct 2023 19:45:21 +0200 Subject: [PATCH 2/3] zlib legacy decompress: call check_fix_size method so we also have the decompressed size in the metadata. --- src/borg/compress.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/borg/compress.pyx b/src/borg/compress.pyx index 3b6deb0d58..d1703f16dc 100644 --- a/src/borg/compress.pyx +++ b/src/borg/compress.pyx @@ -445,7 +445,9 @@ class ZLIB_legacy(CompressorBase): 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 From f0e9999768742083aed51b3c2522b60b7a766330 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 24 Oct 2023 23:33:42 +0200 Subject: [PATCH 3/3] zlib legacy decompress: fix tests --- src/borg/testsuite/compress.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/borg/testsuite/compress.py b/src/borg/testsuite/compress.py index ddcb2267a9..c294b5ff89 100644 --- a/src/borg/testsuite/compress.py +++ b/src/borg/testsuite/compress.py @@ -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