Skip to content

Commit f9103dd

Browse files
TheNeuralBitindygreg
authored andcommitted
tests: add test for calling decompress multiple times
This test was previously failing in the C backend due to the `assert(!self->unused_data)`. The previous commit refactored the code so `self->unused_data` is only assigned after zstd frame completion (not exhaustion of input). So the assertion should be upheld. The bug fixes are also documented in the changelog. Closes #180.
1 parent a1deff5 commit f9103dd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

docs/news.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ Other Actions Not Blocking Release
8282
0.19.0 (not yet released)
8383
=========================
8484

85+
Bug Fixes
86+
---------
87+
88+
* The C backend implementation of ``ZstdDecompressionObj.decompress()`` could
89+
have raised an assertion in cases where the function was called multiple
90+
times on an instance. In non-debug builds, calls to this method could have
91+
leaked memory.
92+
8593
Changes
8694
-------
8795

tests/test_decompressor_decompressobj.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@ def test_reuse(self):
7373
dobj.decompress(data)
7474
self.assertEqual(dobj.flush(), b"")
7575

76+
def test_multiple_decompress_calls(self):
77+
expected = b"foobar" * 10
78+
data = zstd.ZstdCompressor(level=1).compress(expected)
79+
80+
N = 3
81+
partitioned_data = [
82+
data[len(data) * i // N : len(data) * (i + 1) // N]
83+
for i in range(N)
84+
]
85+
86+
dctx = zstd.ZstdDecompressor()
87+
dobj = dctx.decompressobj()
88+
89+
for partition in partitioned_data[:-1]:
90+
decompressed = dobj.decompress(partition)
91+
self.assertEqual(decompressed, b"")
92+
self.assertEqual(dobj.unused_data, b"")
93+
94+
decompressed = dobj.decompress(partitioned_data[-1])
95+
self.assertEqual(decompressed, expected)
96+
7697
def test_bad_write_size(self):
7798
dctx = zstd.ZstdDecompressor()
7899

0 commit comments

Comments
 (0)