mirror of
https://github.com/google/brotli.git
synced 2026-07-08 17:56:58 +00:00
BrotliDecompressedSize fails for certain output sizes #118
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jeroen on GitHub (Jun 5, 2016).
A user of the brotli R library has reported strange behavior of
BrotliDecompressedSizefailing for certain combinations of data and compression size.I put a few example files here. I compressed the file
uncompressedwith quality 3, 4, and 5 and default settings otherwisemode = "generic",log_win = 22,log_block = 0.If I try to decompress the file
compressed3via the C interface, the call toBrotliDecompressedSizefails. It does not happen forcompressed4andcompressed5. Also it does not seem to happen for thebrocommand line utility.@eustas commented on GitHub (Jun 7, 2016):
There is a very limited number of cases in which BrotliDecompressedSize works.
The length of both compressed and uncompressed block is limited to 1 << 24 == 16MiB.
Technically it is possible to make this function work for a case: multiple uncompressed blocks followed by 0 or 1 compressed block.
@eustas commented on GitHub (Jun 7, 2016):
Different compression levels affect ability of encoder to detect better input splitting...
@jeroen commented on GitHub (Jun 7, 2016):
So how is the client supposed to know how much memory to allocate for
BrotliDecompressBufferif we cannot rely onBrotliDecompressedSize?@eustas commented on GitHub (Jun 7, 2016):
Brotli is a low level format. It is designed for streaming processing.
We are planning to add framing format that will allow things like stream navigation, reliable calculation of uncompressed size, consistency checks, etc.
Unfortunately, it is not ready yet...
@jeroen commented on GitHub (Jun 22, 2016):
Perhaps this is mostly a documentation bug then. Without fully understanding technical details of brotli, it seemed the basic API decompressing a buffer was to allocate memory based on
BrotliDecompressedSizeand then invokeBrotliDecompressBuffer.I maintain brotli bindings for the R language. So I suppose I better switch to the
BrotliDecompressStreamAPI to decompress arbitrary brotli data?Can I still use
BrotliCompressBufferfor encoding a buffer or does this API have similar limitations?@eustas commented on GitHub (Jun 24, 2016):
Hello.
Just recently updated
BrotliDecompressedSize. Now it supports multiple non-compressed and metadata blocks. Unfortunately, until brotli framing format is implemented, it will never cover all the cases. So, currently, I would recommend to useBrotliDecompressStream.As for encoder,
BrotliEncoderMaxCompressedSizeprovides the exact answer about how large output may be; but it only works forBrotliEncoderCompress.Thank you for the report and for the R bindings.
Best regards,
Eugene.
@jeroen commented on GitHub (Jun 27, 2016):
Have you pushed the updates for
BrotliDecompressedSizeyet?@eustas commented on GitHub (Jun 27, 2016):
Yup, in PR #386