diff --git a/dissect/util/compression/lzxpress_huffman.py b/dissect/util/compression/lzxpress_huffman.py index 9b81da6..cf4fe08 100644 --- a/dissect/util/compression/lzxpress_huffman.py +++ b/dissect/util/compression/lzxpress_huffman.py @@ -11,6 +11,7 @@ class Symbol(NamedTuple): length: int symbol: int +HUFFMAN_BLOCK_SIZE = 65536 def _read_16_bit(fh: BinaryIO) -> int: return struct.unpack(" bytes: bitstring = BitString() while src.tell() - start_offset < size: + if size - (src.tell() - start_offset) <= 256: + dst.extend(src.read(size - (src.tell() - start_offset))) + return bytes(dst) + root = _build_tree(src.read(256)) bitstring.init(src) chunk_size = 0 - while chunk_size < 65536 and src.tell() - start_offset < size: + while chunk_size < HUFFMAN_BLOCK_SIZE and src.tell() - start_offset < size: symbol = bitstring.decode(root) if symbol < 256: dst.append(symbol)