From 93e3810b0c994b6217cd0d47a98769bbba4c3ec6 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Fri, 15 Apr 2022 11:11:57 -0700 Subject: Fix crash on ota_extractor ota_extractor tries to open source image even for full OTAs. Since we don't pass in source images for full OTAs, the open() call fails. Fix it by only opening source images if incremental OTA is detected. Test: th Change-Id: I903c0faf9e008ff9eb8ee17bfb607b641d87c510 --- aosp/ota_extractor.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/aosp/ota_extractor.cc b/aosp/ota_extractor.cc index 7492bc5a..4a57370f 100644 --- a/aosp/ota_extractor.cc +++ b/aosp/ota_extractor.cc @@ -118,15 +118,21 @@ bool ExtractImagesFromOTA(const DeltaArchiveManifest& manifest, << " size: " << partition.new_partition_info().size(); const auto output_path = output_dir_path.Append(partition.partition_name() + ".img").value(); - const auto input_path = - input_dir_path.Append(partition.partition_name() + ".img").value(); auto out_fd = std::make_shared(); TEST_AND_RETURN_FALSE_ERRNO( out_fd->Open(output_path.c_str(), O_RDWR | O_CREAT, 0644)); auto in_fd = std::make_shared(); - TEST_AND_RETURN_FALSE_ERRNO(in_fd->Open(input_path.c_str(), O_RDONLY)); + if (partition.has_old_partition_info()) { + const auto input_path = + input_dir_path.Append(partition.partition_name() + ".img").value(); + LOG(INFO) << "Incremental OTA detected for partition " + << partition.partition_name() << " opening source image " + << input_path; + CHECK(in_fd->Open(input_path.c_str(), O_RDONLY)) + << " failed to open " << input_path; + } for (const auto& op : partition.operations()) { if (op.has_src_sha256_hash()) { @@ -159,9 +165,11 @@ bool ExtractImagesFromOTA(const DeltaArchiveManifest& manifest, TEST_AND_RETURN_FALSE(executor.ExecuteReplaceOperation( op, std::move(direct_writer), blob.data(), blob.size())); } else if (op.type() == InstallOperation::SOURCE_COPY) { + CHECK(in_fd->IsOpen()); TEST_AND_RETURN_FALSE(executor.ExecuteSourceCopyOperation( op, std::move(direct_writer), in_fd)); } else { + CHECK(in_fd->IsOpen()); TEST_AND_RETURN_FALSE(executor.ExecuteDiffOperation( op, std::move(direct_writer), in_fd, blob.data(), blob.size())); } -- cgit v1.2.3