libsnapshot: Add a test case for recent decompress regression.
The attached test data is a 4096 length byte run that gz compresses to exactly 4096 bytes. This exposes an edge case in CowReader::ReadData with v2 snapshot files. Bug: 310191184 Test: cow_api_test Change-Id: I35e8d7e939d607d1dc118285ebc2f636c2291a20
This commit is contained in:
parent
0ac91e1f02
commit
92b29e1925
3 changed files with 32 additions and 0 deletions
|
@ -420,6 +420,7 @@ cc_test {
|
|||
},
|
||||
data: [
|
||||
"tools/testdata/cow_v2",
|
||||
"tools/testdata/incompressible_block",
|
||||
],
|
||||
auto_gen_config: true,
|
||||
require_root: false,
|
||||
|
|
|
@ -1522,6 +1522,37 @@ TEST_F(CowTest, CompatibilityTest) {
|
|||
ASSERT_TRUE(reader.GetFooter(&footer));
|
||||
}
|
||||
|
||||
TEST_F(CowTest, DecompressIncompressibleBlock) {
|
||||
auto fd = OpenTestFile("incompressible_block", O_RDONLY);
|
||||
ASSERT_GE(fd, 0);
|
||||
|
||||
std::string original;
|
||||
ASSERT_TRUE(android::base::ReadFdToString(fd, &original)) << strerror(errno);
|
||||
ASSERT_EQ(original.size(), 4096);
|
||||
|
||||
CowOptions options;
|
||||
options.compression = "gz";
|
||||
auto writer = CreateCowWriter(2, options, GetCowFd());
|
||||
ASSERT_NE(writer, nullptr);
|
||||
ASSERT_TRUE(writer->AddRawBlocks(0, original.data(), original.size()));
|
||||
ASSERT_TRUE(writer->Finalize());
|
||||
|
||||
CowReader reader;
|
||||
ASSERT_TRUE(reader.Parse(cow_->fd));
|
||||
|
||||
auto iter = reader.GetOpIter();
|
||||
ASSERT_NE(iter, nullptr);
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
|
||||
std::string block(original.size(), '\0');
|
||||
ASSERT_EQ(iter->Get()->data_length, 4096);
|
||||
ASSERT_TRUE(ReadData(reader, iter->Get(), block.data(), block.size()));
|
||||
|
||||
for (size_t i = 0; i < block.size(); i++) {
|
||||
ASSERT_EQ(block[i], original[i]) << "mismatch at byte " << i;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace snapshot
|
||||
} // namespace android
|
||||
|
||||
|
|
BIN
fs_mgr/libsnapshot/tools/testdata/incompressible_block
vendored
Normal file
BIN
fs_mgr/libsnapshot/tools/testdata/incompressible_block
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue