Merge "Fix the bspatch failure on an empty brotli stream" am: e22128bb93

am: 0e031f81b1

Change-Id: I5c6305413856319ae8809ad0084aa630d61bd871
This commit is contained in:
Tianjie Xu authored and android-build-merger committed 2017-11-18 06:22:34 +00:00
commit 424b9dd499
3 files changed
+23 -4

No files matched your search

+15
View File
@@ -37,4 +37,19 @@ TEST(BrotliCompressorTest, BrotliCompressorSmoke) {
decompressed_data);
}
TEST(BrotliCompressorTest, BrotliCompressorEmptyStream) {
uint8_t empty_buffer[] = {};
BrotliCompressor brotli_compressor;
EXPECT_TRUE(brotli_compressor.Write(empty_buffer, sizeof(empty_buffer)));
EXPECT_TRUE(brotli_compressor.Finish());
std::vector<uint8_t> compressed_data = brotli_compressor.GetCompressedData();
// Check that we can close the decompressor without errors.
BrotliDecompressor brotli_decompressor;
EXPECT_TRUE(brotli_decompressor.SetInputData(compressed_data.data(),
compressed_data.size()));
EXPECT_TRUE(brotli_decompressor.Close());
}
} // namespace bsdiff
+6 -1
View File
@@ -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;
}
+2 -3
View File
@@ -72,7 +72,6 @@ class PatchReaderTest : public testing::Test {
std::back_inserter(*patch_data));
}
void VerifyPatch(const std::vector<uint8_t>& patch_data) {
BsdiffPatchReader patch_reader;
EXPECT_TRUE(patch_reader.Init(patch_data.data(), patch_data.size()));
@@ -108,7 +107,7 @@ class PatchReaderTest : public testing::Test {
std::unique_ptr<CompressorInterface> extra_stream_{nullptr};
};
TEST_F(PatchReaderTest, BZ2PatchReaderLegacyFormatSmoke) {
TEST_F(PatchReaderTest, PatchReaderLegacyFormatSmoke) {
ctrl_stream_.reset(new BZ2Compressor());
diff_stream_.reset(new BZ2Compressor());
extra_stream_.reset(new BZ2Compressor());
@@ -123,7 +122,7 @@ TEST_F(PatchReaderTest, BZ2PatchReaderLegacyFormatSmoke) {
VerifyPatch(patch_data);
}
TEST_F(PatchReaderTest, BZ2PatchReaderNewFormatSmoke) {
TEST_F(PatchReaderTest, PatchReaderNewFormatSmoke) {
// Compress the data with one bz2 and two brotli compressors.
ctrl_stream_.reset(new BZ2Compressor());
diff_stream_.reset(new BrotliCompressor());