From 4f81130039f6a312eba2027b3594a2be282f6b3a Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Wed, 16 Sep 2020 14:06:12 -0400 Subject: Switch to zip64 in recovery There's already library support for zip64 in libziparchive. We just need to start using the new APIs. Bug: 167951876 Test: Sideload a large ota package in recovery Change-Id: I652741965f28de079d873c6822317ee9fa855201 --- applypatch/imgdiff.cpp | 6 +++--- applypatch/include/applypatch/imgdiff_image.h | 3 ++- install/install.cpp | 8 ++++---- install/verifier.cpp | 2 +- install/wipe_device.cpp | 2 +- tests/unit/install_test.cpp | 2 +- tests/unit/package_test.cpp | 2 +- tests/unit/zip_test.cpp | 2 +- updater/blockimg.cpp | 8 ++++---- updater/install.cpp | 4 ++-- updater/target_files.cpp | 6 +++--- updater/updater.cpp | 2 +- 12 files changed, 24 insertions(+), 23 deletions(-) diff --git a/applypatch/imgdiff.cpp b/applypatch/imgdiff.cpp index 85860281a..d0cb687cb 100644 --- a/applypatch/imgdiff.cpp +++ b/applypatch/imgdiff.cpp @@ -682,9 +682,9 @@ bool ZipModeImage::InitializeChunks(const std::string& filename, ZipArchiveHandl } // Create a list of deflated zip entries, sorted by offset. - std::vector> temp_entries; + std::vector> temp_entries; std::string name; - ZipEntry entry; + ZipEntry64 entry; while ((ret = Next(cookie, &entry, &name)) == 0) { if (entry.method == kCompressDeflated || limit_ > 0) { temp_entries.emplace_back(name, entry); @@ -757,7 +757,7 @@ bool ZipModeImage::InitializeChunks(const std::string& filename, ZipArchiveHandl } bool ZipModeImage::AddZipEntryToChunks(ZipArchiveHandle handle, const std::string& entry_name, - ZipEntry* entry) { + ZipEntry64* entry) { size_t compressed_len = entry->compressed_length; if (compressed_len == 0) return true; diff --git a/applypatch/include/applypatch/imgdiff_image.h b/applypatch/include/applypatch/imgdiff_image.h index aa8d129c3..b579e56ae 100644 --- a/applypatch/include/applypatch/imgdiff_image.h +++ b/applypatch/include/applypatch/imgdiff_image.h @@ -257,7 +257,8 @@ class ZipModeImage : public Image { // Initialize image chunks based on the zip entries. bool InitializeChunks(const std::string& filename, ZipArchiveHandle handle); // Add the a zip entry to the list. - bool AddZipEntryToChunks(ZipArchiveHandle handle, const std::string& entry_name, ZipEntry* entry); + bool AddZipEntryToChunks(ZipArchiveHandle handle, const std::string& entry_name, + ZipEntry64* entry); // Return the real size of the zip file. (omit the trailing zeros that used for alignment) bool GetZipFileSize(size_t* input_file_size); diff --git a/install/install.cpp b/install/install.cpp index 1c711f6b3..753373206 100644 --- a/install/install.cpp +++ b/install/install.cpp @@ -77,7 +77,7 @@ bool ReadMetadataFromPackage(ZipArchiveHandle zip, std::map IterateZipEntriesAndSearchForKeys(const ZipArchi std::vector result; std::string_view name; - ZipEntry entry; + ZipEntry64 entry; while ((iter_status = Next(cookie, &entry, &name)) == 0) { std::vector pem_content(entry.uncompressed_length); if (int32_t extract_status = diff --git a/install/wipe_device.cpp b/install/wipe_device.cpp index 89d5d31a3..0f896c43b 100644 --- a/install/wipe_device.cpp +++ b/install/wipe_device.cpp @@ -49,7 +49,7 @@ std::vector GetWipePartitionList(Package* wipe_package) { constexpr char RECOVERY_WIPE_ENTRY_NAME[] = "recovery.wipe"; std::string partition_list_content; - ZipEntry entry; + ZipEntry64 entry; if (FindEntry(zip, RECOVERY_WIPE_ENTRY_NAME, &entry) == 0) { uint32_t length = entry.uncompressed_length; partition_list_content = std::string(length, '\0'); diff --git a/tests/unit/install_test.cpp b/tests/unit/install_test.cpp index fc7c2bf2f..c3415479d 100644 --- a/tests/unit/install_test.cpp +++ b/tests/unit/install_test.cpp @@ -190,7 +190,7 @@ static void VerifyAbUpdateCommands(const std::string& serialno, bool success = t ZipArchiveHandle zip; ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); - ZipEntry payload_entry; + ZipEntry64 payload_entry; ASSERT_EQ(0, FindEntry(zip, "payload.bin", &payload_entry)); std::map metadata; diff --git a/tests/unit/package_test.cpp b/tests/unit/package_test.cpp index 5e31f7fa5..164a93d57 100644 --- a/tests/unit/package_test.cpp +++ b/tests/unit/package_test.cpp @@ -106,7 +106,7 @@ TEST_F(PackageTest, GetZipArchiveHandle_extract_entry) { // Check that we can extract one zip entry. std::string_view entry_name = "dir1/file3.txt"; - ZipEntry entry; + ZipEntry64 entry; ASSERT_EQ(0, FindEntry(zip, entry_name, &entry)); std::vector extracted(entry_name.size()); diff --git a/tests/unit/zip_test.cpp b/tests/unit/zip_test.cpp index ec9585c79..e065bb859 100644 --- a/tests/unit/zip_test.cpp +++ b/tests/unit/zip_test.cpp @@ -37,7 +37,7 @@ TEST(ZipTest, OpenFromMemory) { ASSERT_EQ(0, OpenArchiveFromMemory(map.addr, map.length, zip_path.c_str(), &handle)); static constexpr const char* BINARY_PATH = "META-INF/com/google/android/update-binary"; - ZipEntry binary_entry; + ZipEntry64 binary_entry; // Make sure the package opens correctly and its entry can be read. ASSERT_EQ(0, FindEntry(handle, BINARY_PATH, &binary_entry)); diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index 2d41f610b..b29aa8ce3 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp @@ -348,7 +348,7 @@ class RangeSinkWriter { */ struct NewThreadInfo { ZipArchiveHandle za; - ZipEntry entry; + ZipEntry64 entry{}; bool brotli_compressed; std::unique_ptr writer; @@ -1626,7 +1626,7 @@ static bool Sha1DevicePath(const std::string& path, uint8_t digest[SHA_DIGEST_LE static Value* PerformBlockImageUpdate(const char* name, State* state, const std::vector>& argv, const CommandMap& command_map, bool dryrun) { - CommandParameters params = {}; + CommandParameters params{}; stash_map.clear(); params.canwrite = !dryrun; @@ -1687,7 +1687,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, } std::string_view path_data(patch_data_fn->data); - ZipEntry patch_entry; + ZipEntry64 patch_entry; if (FindEntry(za, path_data, &patch_entry) != 0) { LOG(ERROR) << name << "(): no file \"" << patch_data_fn->data << "\" in package"; return StringValue(""); @@ -1695,7 +1695,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, params.patch_start = updater->GetMappedPackageAddress() + patch_entry.offset; std::string_view new_data(new_data_fn->data); - ZipEntry new_entry; + ZipEntry64 new_entry; if (FindEntry(za, new_data, &new_entry) != 0) { LOG(ERROR) << name << "(): no file \"" << new_data_fn->data << "\" in package"; return StringValue(""); diff --git a/updater/install.cpp b/updater/install.cpp index afa5195d0..cfa4d9d82 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -115,7 +115,7 @@ Value* PackageExtractFileFn(const char* name, State* state, std::string dest_path = args[1]; ZipArchiveHandle za = state->updater->GetPackageHandle(); - ZipEntry entry; + ZipEntry64 entry; if (FindEntry(za, zip_path, &entry) != 0) { LOG(ERROR) << name << ": no " << zip_path << " in package"; return StringValue(""); @@ -165,7 +165,7 @@ Value* PackageExtractFileFn(const char* name, State* state, const std::string& zip_path = args[0]; ZipArchiveHandle za = state->updater->GetPackageHandle(); - ZipEntry entry; + ZipEntry64 entry; if (FindEntry(za, zip_path, &entry) != 0) { return ErrorAbort(state, kPackageExtractFileFailure, "%s(): no %s in package", name, zip_path.c_str()); diff --git a/updater/target_files.cpp b/updater/target_files.cpp index 919ec4e04..951923293 100644 --- a/updater/target_files.cpp +++ b/updater/target_files.cpp @@ -115,7 +115,7 @@ bool TargetFile::EntryExists(const std::string_view name) const { } CHECK(handle_); - ZipEntry img_entry; + ZipEntry64 img_entry; return FindEntry(handle_, name, &img_entry) == 0; } @@ -126,7 +126,7 @@ bool TargetFile::ReadEntryToString(const std::string_view name, std::string* con } CHECK(handle_); - ZipEntry entry; + ZipEntry64 entry; if (auto find_err = FindEntry(handle_, name, &entry); find_err != 0) { LOG(ERROR) << "failed to find " << name << " in the package: " << ErrorCodeString(find_err); return false; @@ -157,7 +157,7 @@ bool TargetFile::ExtractEntryToTempFile(const std::string_view name, } CHECK(handle_); - ZipEntry entry; + ZipEntry64 entry; if (auto find_err = FindEntry(handle_, name, &entry); find_err != 0) { LOG(ERROR) << "failed to find " << name << " in the package: " << ErrorCodeString(find_err); return false; diff --git a/updater/updater.cpp b/updater/updater.cpp index 8f4a6ede5..73ca0e532 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -163,7 +163,7 @@ void Updater::ParseAndReportErrorCode(State* state) { bool Updater::ReadEntryToString(ZipArchiveHandle za, const std::string& entry_name, std::string* content) { - ZipEntry entry; + ZipEntry64 entry; int find_err = FindEntry(za, entry_name, &entry); if (find_err != 0) { LOG(ERROR) << "failed to find " << entry_name -- cgit v1.2.3