]> git.ipfire.org Git - thirdparty/zstd.git/commit
Fix super block compression and stream raw blocks in decompression (#1947)
authorNick Terrell <terrelln@fb.com>
Sat, 11 Jan 2020 02:02:11 +0000 (18:02 -0800)
committerGitHub <noreply@github.com>
Sat, 11 Jan 2020 02:02:11 +0000 (18:02 -0800)
commit036b30b555e846dfccc435d781e402b4d38b3c8d
tree9e96bca3e2fb84eba80832f6b6ec349f1acf444c
parentf25a6e9f8f36375bce85bfefdf388c770057c27c
Fix super block compression and stream raw blocks in decompression (#1947)

Super blocks must never violate the zstd block bound of input_size + ZSTD_blockHeaderSize. The individual sub-blocks may, but not the super block. If the superblock violates the block bound we are liable to violate ZSTD_compressBound(), which we must not do. Whenever the super block violates the block bound we instead emit an uncompressed block.

This means we increase the latency because of the single uncompressed block. I fix this by enabling streaming an uncompressed block, so the latency of an uncompressed block is 1 byte. This doesn't reduce the latency of the buffer-less API, but I don't think we really care.

* I added a test case that verifies that the decompression has 1 byte latency.
* I rely on existing zstreamtest / fuzzer / libfuzzer regression tests for correctness. During development I had several correctness bugs, and they easily caught them.
* The added assert that the superblock doesn't violate the block bound will help us discover any missed conditions (though I think I got them all).

Credit to OSS-Fuzz.
lib/compress/zstd_compress.c
lib/compress/zstd_compress_superblock.c
lib/compress/zstd_compress_superblock.h
lib/decompress/zstd_decompress.c
tests/zstreamtest.c