twrpinstall: Switch to ZipEntry64

The libziparchive TWRP using was outdated, not supported a zip
size more than 4 GiB. With the development of technologies,
Obviously it was not enough for ROM packages, like Xiaomi's
MIUI for Vitrual A/B devices (for example Redmi K40 [alioth])
is more than 4 GiB and TWRP couldn't handle it properly.
Since we have updated libziparchive to latest version, we could
switch ZipEntry to ZipEntry64 so that TWRP can support a ROM
package if its size more than 4 GiB.

Co-authored-by: sekaiacg <sekaiacg@gmail.com>
Signed-off-by: GarfieldHan <2652609017@qq.com>
Change-Id: Iee811554bb08e02bf2bd8e9057511f36caefdc9d
This commit is contained in:
GarfieldHan
2021-11-29 00:04:53 +08:00
committed by bigbiff
parent 36cb2ad28e
commit b3f6a26422
5 changed files with 20 additions and 20 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ bool ExtractPackageRecursive(ZipArchiveHandle zip, const std::string& zip_path,
}
std::unique_ptr<void, decltype(&EndIteration)> guard(cookie, EndIteration);
ZipEntry entry;
ZipEntry64 entry;
ZipString name;
int extractCount = 0;
while (Next(cookie, &entry, &name) == 0) {
+7 -7
View File
@@ -72,7 +72,7 @@ bool ReadMetadataFromPackage(ZipArchiveHandle zip, std::map<std::string, std::st
static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata";
std::string path(METADATA_PATH);
ZipEntry entry;
ZipEntry64 entry;
if (FindEntry(zip, path, &entry) != 0) {
LOG(ERROR) << "Failed to find " << METADATA_PATH;
return false;
@@ -235,7 +235,7 @@ int SetUpAbUpdateCommands(const std::string& package, ZipArchiveHandle zip, int
// in the zip file.
static constexpr const char* AB_OTA_PAYLOAD_PROPERTIES = "payload_properties.txt";
std::string property_name(AB_OTA_PAYLOAD_PROPERTIES);
ZipEntry properties_entry;
ZipEntry64 properties_entry;
if (FindEntry(zip, property_name, &properties_entry) != 0) {
LOG(ERROR) << "Failed to find " << AB_OTA_PAYLOAD_PROPERTIES;
return INSTALL_CORRUPT;
@@ -251,7 +251,7 @@ int SetUpAbUpdateCommands(const std::string& package, ZipArchiveHandle zip, int
static constexpr const char* AB_OTA_PAYLOAD = "payload.bin";
std::string payload_name(AB_OTA_PAYLOAD);
ZipEntry payload_entry;
ZipEntry64 payload_entry;
if (FindEntry(zip, payload_name, &payload_entry) != 0) {
LOG(ERROR) << "Failed to find " << AB_OTA_PAYLOAD;
return INSTALL_CORRUPT;
@@ -273,7 +273,7 @@ int SetUpNonAbUpdateCommands(const std::string& package, ZipArchiveHandle zip, i
// In non-A/B updates we extract the update binary from the package.
std::string binary_name(UPDATE_BINARY_NAME);
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(zip, binary_name, &binary_entry) != 0) {
LOG(ERROR) << "Failed to find update binary " << UPDATE_BINARY_NAME;
return INSTALL_CORRUPT;
@@ -390,7 +390,7 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b
is_ab = false;
std::string binary_name(UPDATE_BINARY_NAME);
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(zip, binary_name, &binary_entry) != 0) {
LOG(ERROR) << "Failed to find update binary " << UPDATE_BINARY_NAME;
is_ab = true;
@@ -521,7 +521,7 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b
// static constexpr const char* COMPATIBILITY_ZIP_ENTRY = "compatibility.zip";
// ZipString compatibility_entry_name(COMPATIBILITY_ZIP_ENTRY);
// ZipEntry compatibility_entry;
// ZipEntry64 compatibility_entry;
// if (FindEntry(package_zip, compatibility_entry_name, &compatibility_entry) != 0) {
// LOG(INFO) << "Package doesn't contain " << COMPATIBILITY_ZIP_ENTRY << " entry";
// return true;
@@ -555,7 +555,7 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b
// std::unique_ptr<void, decltype(&EndIteration)> guard(cookie, EndIteration);
// std::vector<std::string> compatibility_info;
// ZipEntry info_entry;
// ZipEntry64 info_entry;
// ZipString info_name;
// while (Next(cookie, &info_entry, &info_name) == 0) {
// std::string content(info_entry.uncompressed_length, '\0');
+5 -5
View File
@@ -55,7 +55,7 @@ static int parse_build_number(std::string str) {
bool read_metadata_from_package(ZipArchiveHandle zip, std::string* meta_data) {
std::string binary_name(METADATA_PATH);
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(zip, binary_name, &binary_entry) == 0) {
long size = binary_entry.uncompressed_length;
if (size <= 0)
@@ -201,7 +201,7 @@ abupdate_binary_command(const char* path, int retry_count __unused,
// the RAW payload offset in the zip file.
// if (!Zip->EntryExists(AB_OTA_PAYLOAD_PROPERTIES)) {
std::string binary_name(AB_OTA_PAYLOAD_PROPERTIES);
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(Zip, binary_name, &binary_entry) != 0) {
printf("Can't find %s\n", AB_OTA_PAYLOAD_PROPERTIES);
return INSTALL_CORRUPT;
@@ -216,7 +216,7 @@ abupdate_binary_command(const char* path, int retry_count __unused,
}
std::string ab_ota_payload(AB_OTA_PAYLOAD);
ZipEntry ab_ota_payload_entry;
ZipEntry64 ab_ota_payload_entry;
if (FindEntry(Zip, ab_ota_payload, &ab_ota_payload_entry) != 0) {
printf("Can't find %s\n", AB_OTA_PAYLOAD);
return INSTALL_CORRUPT;
@@ -277,7 +277,7 @@ bool verify_package_compatibility(ZipArchiveHandle zw) {
static constexpr const char* COMPATIBILITY_ZIP_ENTRY = "compatibility.zip";
std::string compatibility_entry_name(COMPATIBILITY_ZIP_ENTRY);
ZipEntry compatibility_entry;
ZipEntry64 compatibility_entry;
if (FindEntry(zw, compatibility_entry_name, &compatibility_entry) != 0) {
printf("Package doesn't contain %s entry\n", COMPATIBILITY_ZIP_ENTRY);
return true;
@@ -311,7 +311,7 @@ bool verify_package_compatibility(ZipArchiveHandle zw) {
std::unique_ptr<void, decltype(&EndIteration)> guard(cookie, EndIteration);
std::vector<std::string> compatibility_info;
ZipEntry info_entry;
ZipEntry64 info_entry;
std::string info_name;
while (Next(cookie, &info_entry, &info_name) == 0) {
std::string content(info_entry.uncompressed_length, '\0');
+6 -6
View File
@@ -74,7 +74,7 @@ static int Install_Theme(const char* path, ZipArchiveHandle Zip) {
return INSTALL_CORRUPT;
#else
std::string binary_name("ui.xml");
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(Zip, binary_name, &binary_entry) != 0) {
return INSTALL_CORRUPT;
}
@@ -106,7 +106,7 @@ static int Prepare_Update_Binary(ZipArchiveHandle Zip) {
std::vector<string>::iterator arch;
std::string base_name = UPDATE_BINARY_NAME;
base_name += "-";
ZipEntry binary_entry;
ZipEntry64 binary_entry;
std::string update_binary_string(UPDATE_BINARY_NAME);
if (FindEntry(Zip, update_binary_string, &binary_entry) != 0) {
for (arch = split.begin(); arch != split.end(); arch++) {
@@ -133,7 +133,7 @@ static int Prepare_Update_Binary(ZipArchiveHandle Zip) {
// If exists, extract file_contexts from the zip file
std::string file_contexts("file_contexts");
ZipEntry file_contexts_entry;
ZipEntry64 file_contexts_entry;
if (FindEntry(Zip, file_contexts, &file_contexts_entry) != 0) {
LOGINFO("Zip does not contain SELinux file_contexts file in its root.\n");
} else {
@@ -309,7 +309,7 @@ int TWinstall_zip(const char* path, int* wipe_cache, bool check_for_digest) {
time(&start);
std::string update_binary_name(UPDATE_BINARY_NAME);
ZipEntry update_binary_entry;
ZipEntry64 update_binary_entry;
if (FindEntry(Zip, update_binary_name, &update_binary_entry) == 0) {
LOGINFO("Update binary zip\n");
// Additionally verify the compatibility of the package.
@@ -323,7 +323,7 @@ int TWinstall_zip(const char* path, int* wipe_cache, bool check_for_digest) {
}
} else {
std::string ab_binary_name(AB_OTA);
ZipEntry ab_binary_entry;
ZipEntry64 ab_binary_entry;
if (FindEntry(Zip, ab_binary_name, &ab_binary_entry) == 0) {
LOGINFO("AB zip\n");
gui_msg(Msg(msg::kHighlight, "flash_ab_inactive=Flashing A/B zip to inactive slot: {1}")(PartitionManager.Get_Active_Slot_Display()=="A"?"B":"A"));
@@ -353,7 +353,7 @@ int TWinstall_zip(const char* path, int* wipe_cache, bool check_for_digest) {
}
} else {
std::string binary_name("ui.xml");
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(Zip, binary_name, &binary_entry) != 0) {
LOGINFO("TWRP theme zip\n");
ret_val = Install_Theme(path, Zip);
+1 -1
View File
@@ -328,7 +328,7 @@ static std::vector<Certificate> IterateZipEntriesAndSearchForKeys(const ZipArchi
std::vector<Certificate> result;
std::string_view name;
ZipEntry entry;
ZipEntry64 entry;
while ((iter_status = Next(cookie, &entry, &name)) == 0) {
std::vector<uint8_t> pem_content(entry.uncompressed_length);
if (int32_t extract_status =