mirror of
https://github.com/expo/bsdiff.git
synced 2026-11-14 17:49:03 -10:00
Merge "Fix the bspatch failure on an empty brotli stream"
am: e22128bb93
Change-Id: Ia41abe71179bcb2b865c6c26d72b3d7cb3afc8cf
This commit is contained in:
commit
0e031f81b1
3 files changed
+23
-4
No files matched your search
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in new issue
Block a user