diff --git a/CHANGELOG.md b/CHANGELOG.md index 27709d3..e393731 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## Unreleased + +- Fix issue with `max_length` not always being respected in `EndlessZstdDecompressor` + ## 0.20.0 (October 11, 2026) - Support for 3.15 and PyPy 3.12 diff --git a/src/pyzstd/__init__.py b/src/pyzstd/__init__.py index 37fce65..73455ad 100644 --- a/src/pyzstd/__init__.py +++ b/src/pyzstd/__init__.py @@ -368,20 +368,22 @@ def decompress(self, data: Buffer, max_length: int = -1) -> bytes: raise TypeError self._buffer += data self._at_frame_edge &= not self._buffer - out = b"" + out_chunks: list[bytes] = [] while True: try: - out += self._decompressor.decompress(self._buffer, max_length) + out_chunks.append( + self._decompressor.decompress(self._buffer, max_length) + ) except ZstdError: self._reset() raise if self._decompressor.eof: self._reset(self._decompressor.unused_data) - max_length -= len(out) + max_length -= len(out_chunks[-1]) else: self._buffer = b"" break - return out + return b"".join(out_chunks) @property def at_frame_edge(self) -> bool: