Merge "libsnapshot: Validate Sequence Op data"

This commit is contained in:
Daniel Rosenberg 2021-07-29 22:40:04 +00:00 committed by Gerrit Code Review
commit 3acae5450f
2 changed files with 28 additions and 0 deletions

View file

@ -1013,6 +1013,27 @@ TEST_F(CowTest, BigSeqOp) {
ASSERT_TRUE(iter->Done());
}
TEST_F(CowTest, MissingSeqOp) {
CowOptions options;
CowWriter writer(options);
const int seq_len = 10;
uint32_t sequence[seq_len];
for (int i = 0; i < seq_len; i++) {
sequence[i] = i + 1;
}
ASSERT_TRUE(writer.Initialize(cow_->fd));
ASSERT_TRUE(writer.AddSequenceData(seq_len, sequence));
ASSERT_TRUE(writer.AddZeroBlocks(1, seq_len - 1));
ASSERT_TRUE(writer.Finalize());
ASSERT_EQ(lseek(cow_->fd, 0, SEEK_SET), 0);
CowReader reader;
ASSERT_FALSE(reader.Parse(cow_->fd));
}
TEST_F(CowTest, RevMergeOpItrTest) {
CowOptions options;
options.cluster_ops = 5;

View file

@ -413,6 +413,13 @@ bool CowReader::PrepMergeOps() {
}
block_map->insert({current_op.new_block, i});
}
for (auto block : *merge_op_blocks) {
if (block_map->count(block) == 0) {
LOG(ERROR) << "Invalid Sequence Ops. Could not find Cow Op for new block " << block;
return false;
}
}
if (merge_op_blocks->size() > header_.num_merge_ops) {
num_ordered_ops_to_merge_ = merge_op_blocks->size() - header_.num_merge_ops;
} else {