From c2a048e2ed223b3a9c5e171aa5712a52ed1c45ee Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Fri, 1 May 2020 11:41:56 -0700 Subject: [PATCH] Handle zero snapshot size appropriately. This won't happen in practice because device size is never zero. Hypothetically, if it is, PartitionCowCreator still suggests that a CoW size of 8192 bytes needs to be created. In reality, it is not necessary. Test: libsnapshot_fuzzer Bug: 155484992 Change-Id: I6c69f54820522d50c699384eec90c474ca3a9402 (cherry picked from commit bc84824e21acfdc83590d6d0d4827bd9854fc0f5) Merged-In: I6c69f54820522d50c699384eec90c474ca3a9402 --- fs_mgr/libsnapshot/partition_cow_creator.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs_mgr/libsnapshot/partition_cow_creator.cpp b/fs_mgr/libsnapshot/partition_cow_creator.cpp index efdb59f78..0df5664fd 100644 --- a/fs_mgr/libsnapshot/partition_cow_creator.cpp +++ b/fs_mgr/libsnapshot/partition_cow_creator.cpp @@ -181,6 +181,13 @@ std::optional PartitionCowCreator::Run() { ret.snapshot_status.set_device_size(target_partition->size()); ret.snapshot_status.set_snapshot_size(target_partition->size()); + if (ret.snapshot_status.snapshot_size() == 0) { + LOG(INFO) << "Not creating snapshot for partition " << ret.snapshot_status.name(); + ret.snapshot_status.set_cow_partition_size(0); + ret.snapshot_status.set_cow_file_size(0); + return ret; + } + // Being the COW partition virtual, its size doesn't affect the storage // memory that will be occupied by the target. // The actual storage space is affected by the COW file, whose size depends