diff options
author | Alex Deymo <deymo@google.com> | 2018-03-21 19:50:06 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-03-21 19:50:06 +0000 |
commit | 1120e32f2481bab871b8b00ce300365e71f72714 (patch) | |
tree | 2c2198d0f184a656a33ae74a298537c73e0a574f | |
parent | 8ccc9ed5156589f46b6e4d9ea5c555dbc9ae1a89 (diff) | |
parent | bf07c41aaed0081e0cd615fb15eae903452b667e (diff) | |
download | bsdiff-1120e32f2481bab871b8b00ce300365e71f72714.tar.gz |
Merge "Added more unittests for invalid patch formats."
am: bf07c41aae
Change-Id: Iddf2cbebb8d27023db9983527d11e9e327229c0b
-rw-r--r-- | patch_reader_unittest.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/patch_reader_unittest.cc b/patch_reader_unittest.cc index e3b32a9..8de346d 100644 --- a/patch_reader_unittest.cc +++ b/patch_reader_unittest.cc @@ -196,5 +196,49 @@ TEST_F(PatchReaderTest, InvalidHeaderTest) { InvalidHeaderTestHelper(kMax64 - 5, kMax64 - 5, 20, 20); } +TEST_F(PatchReaderTest, InvalidCompressionHeaderTest) { + std::vector<uint8_t> patch_data; + std::copy(kBSDF2MagicHeader, kBSDF2MagicHeader + 5, + std::back_inserter(patch_data)); + // Set an invalid compression value. + patch_data.push_back(99); + patch_data.push_back(static_cast<uint8_t>(CompressorType::kBrotli)); + patch_data.push_back(static_cast<uint8_t>(CompressorType::kBrotli)); + ConstructPatchHeader(10, 10, 10, &patch_data); + patch_data.resize(patch_data.size() + 30); + + BsdiffPatchReader patch_reader; + EXPECT_FALSE(patch_reader.Init(patch_data.data(), patch_data.size())); +} + +TEST_F(PatchReaderTest, InvalidControlEntryTest) { + // Check that negative diff and extra values in a control entry are not + // allowed. + ctrl_stream_.reset(new BZ2Compressor()); + diff_stream_.reset(new BrotliCompressor(11)); + extra_stream_.reset(new BrotliCompressor(11)); + + // Encode the header. + uint8_t buf[24]; + EncodeInt64(-10, buf); + EncodeInt64(0, buf + 8); + EncodeInt64(0, buf + 16); + ctrl_stream_->Write(buf, sizeof(buf)); + + CompressData(); + + std::vector<uint8_t> patch_data; + std::copy(kBSDF2MagicHeader, kBSDF2MagicHeader + 5, + std::back_inserter(patch_data)); + patch_data.push_back(static_cast<uint8_t>(CompressorType::kBZ2)); + patch_data.push_back(static_cast<uint8_t>(CompressorType::kBrotli)); + patch_data.push_back(static_cast<uint8_t>(CompressorType::kBrotli)); + ConstructPatchData(&patch_data); + + BsdiffPatchReader patch_reader; + EXPECT_TRUE(patch_reader.Init(patch_data.data(), patch_data.size())); + ControlEntry control_entry(0, 0, 0); + EXPECT_FALSE(patch_reader.ParseControlEntry(&control_entry)); +} } // namespace bsdiff |