summaryrefslogtreecommitdiff
path: root/brotli_decompressor.cc
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2017-11-17 16:06:30 -0800
committerTianjie Xu <xunchang@google.com>2017-11-17 16:54:05 -0800
commitd4875cd3207eb21a992796b23151546e5bd4bf5c (patch)
treeec48cc852bd6266ae6c29fc855df3aab4ec09b27 /brotli_decompressor.cc
parent2ab0083e1eae29dfb27f1cf005a4a1c26e5612f9 (diff)
downloadbsdiff-d4875cd3207eb21a992796b23151546e5bd4bf5c.tar.gz
Fix the bspatch failure on an empty brotli stream
When we close the BrotliDecompressor, we check for BrotliDecoderIsFinished(). This function may return false if we never call BrotliDecoderDecompressStream(), leading to a failure in bspatch in case of an empty brotli stream. This CL fixes the issue by checking BrotliDecoderIsUsed() along with IsFinished(). Since we have the compressed stream and the precomputed uncompressed size in the patch; we need these checks to avoid unexpected size mismatch. Bug: 69472150 Test: unittest pass Change-Id: Icf7b324836fa59fd3111ba91b03622215a0c8f5f
Diffstat (limited to 'brotli_decompressor.cc')
-rw-r--r--brotli_decompressor.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/brotli_decompressor.cc b/brotli_decompressor.cc
index 683e391..f173a75 100644
--- a/brotli_decompressor.cc
+++ b/brotli_decompressor.cc
@@ -49,7 +49,12 @@ bool BrotliDecompressor::Read(uint8_t* output_data, size_t bytes_to_output) {
}
bool BrotliDecompressor::Close() {
- if (!BrotliDecoderIsFinished(brotli_decoder_state_)) {
+ // In some cases, the brotli compressed stream could be empty. As a result,
+ // the function BrotliDecoderIsFinished() will return false because we never
+ // start the decompression. When that happens, we just destroy the decoder
+ // and return true.
+ if (BrotliDecoderIsUsed(brotli_decoder_state_) &&
+ !BrotliDecoderIsFinished(brotli_decoder_state_)) {
LOG(ERROR) << "Unfinished brotli decoder." << endl;
return false;
}