compression_utils
Decompression of data that arrives from off this host.
Module
Functions
zstd_decompress_bounded
def zstd_decompress_bounded(data: bytes, max_output_size: int) ‑> bytes:Decompresses zstd data, refusing output larger than max_output_size.
zstandard.decompress's own max_output_size argument does not do this. It
applies only to a frame whose header does not declare its content size; a
frame that does declare one is allocated at the declared size whatever the
argument says. Twelve kilobytes on the wire therefore becomes hundreds of
megabytes of resident memory, and the sender chooses how many. So the
output is accumulated here and abandoned as soon as it passes the limit.
Arguments
data: The compressed frame.max_output_size: The largest decompressed output to return, in bytes.
Returns The decompressed bytes.
Raises
zstandard.ZstdError: Ifdatais not a valid zstd frame, or if its output exceedsmax_output_size. Decompressing invalid data already raised this, so a caller that tolerated one tolerates the other.