From 070848b9efe606454f0f9e35df43b37c5db3cf1b Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Wed, 3 Jan 2024 14:22:54 -0800 Subject: [PATCH] libsnapshot: add check for updating next_data_pos_ Adding a check here to ensure that next_data_pos_ isn't modified since initialization. After sizing the sequence buffer, this value should be the initialized value + the size of sequence buffer. Test: cow_api_test Change-Id: I9c79041b72544500989860a13ca6c25830d28750 --- fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp index bd69ac685..e73684738 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp +++ b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp @@ -399,8 +399,14 @@ bool CowWriterV3::EmitSequenceData(size_t num_ops, const uint32_t* data) { "operation writes."; return false; } + header_.sequence_data_count = num_ops; + + // Ensure next_data_pos_ is updated as previously initialized + the newly added sequence buffer. + CHECK_EQ(next_data_pos_ + header_.sequence_data_count * sizeof(uint32_t), + GetDataOffset(header_)); next_data_pos_ = GetDataOffset(header_); + if (!android::base::WriteFullyAtOffset(fd_, data, sizeof(data[0]) * num_ops, GetSequenceOffset(header_))) { PLOG(ERROR) << "writing sequence buffer failed";