aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2023-06-17 22:12:26 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-06-17 22:12:26 +0000
commit57c1aa7b1605881a753f89ee467f3aecf5851f7e (patch)
tree759d00a3c68bfaf6a605df359eb4144395871a56
parent0d2d11bc00556550adfe6ccb25aa0c85281f5744 (diff)
parent1e774245a4dd2763545827d65462e5c115eecb63 (diff)
downloadbuild-57c1aa7b1605881a753f89ee467f3aecf5851f7e.tar.gz
Merge "Handle zip64 extra fields better"
-rwxr-xr-xtools/releasetools/check_target_files_signatures.py5
-rw-r--r--tools/releasetools/common.py18
-rwxr-xr-xtools/releasetools/ota_from_target_files.py19
3 files changed, 30 insertions, 12 deletions
diff --git a/tools/releasetools/check_target_files_signatures.py b/tools/releasetools/check_target_files_signatures.py
index d935607e43..a7b35230ea 100755
--- a/tools/releasetools/check_target_files_signatures.py
+++ b/tools/releasetools/check_target_files_signatures.py
@@ -241,7 +241,8 @@ class APK(object):
# Signer (minSdkVersion=24, maxSdkVersion=32) certificate SHA-1 digest: 19da94896ce4078c38ca695701f1dec741ec6d67
# ...
certs_info = {}
- certificate_regex = re.compile(r"(Signer (?:#[0-9]+|\(.*\))) (certificate .*):(.*)")
+ certificate_regex = re.compile(
+ r"(Signer (?:#[0-9]+|\(.*\))) (certificate .*):(.*)")
for line in output.splitlines():
m = certificate_regex.match(line)
if not m:
@@ -312,7 +313,7 @@ class TargetFiles(object):
# This is the list of wildcards of files we extract from |filename|.
apk_extensions = ['*.apk', '*.apex']
- with zipfile.ZipFile(filename) as input_zip:
+ with zipfile.ZipFile(filename, "r") as input_zip:
self.certmap, compressed_extension = common.ReadApkCerts(input_zip)
if compressed_extension:
apk_extensions.append('*.apk' + compressed_extension)
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index d33397b9a3..f00c1a9d4f 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -2135,9 +2135,23 @@ def UnzipToDir(filename, dirname, patterns=None):
# to indicate the actual local header offset.
# As of python3.11, python does not handle zip64 central directories
# correctly, so we will manually do the parsing here.
+
+ # ZIP64 central directory extra field has two required fields:
+ # 2 bytes header ID and 2 bytes size field. Thes two require fields have
+ # a total size of 4 bytes. Then it has three other 8 bytes field, followed
+ # by a 4 byte disk number field. The last disk number field is not required
+ # to be present, but if it is present, the total size of extra field will be
+ # divisible by 8(because 2+2+4+8*n is always going to be multiple of 8)
+ # Most extra fields are optional, but when they appear, their must appear
+ # in the order defined by zip64 spec. Since file header offset is the 2nd
+ # to last field in zip64 spec, it will only be at last 8 bytes or last 12-4
+ # bytes, depending on whether disk number is present.
for entry in entries:
- if entry.header_offset == 0xFFFFFFFF and len(entry.extra) >= 28:
- entry.header_offset = int.from_bytes(entry.extra[20:28], "little")
+ if entry.header_offset == 0xFFFFFFFF:
+ if len(entry.extra) % 8 == 0:
+ entry.header_offset = int.from_bytes(entry.extra[-12:-4], "little")
+ else:
+ entry.header_offset = int.from_bytes(entry.extra[-8:], "little")
if patterns is not None:
filtered = [info for info in entries if any(
[fnmatch.fnmatch(info.filename, p) for p in patterns])]
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index 4c0d391f8e..f3e6f1e3d1 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -633,14 +633,17 @@ def GetTargetFilesZipForPartialUpdates(input_file, ab_partitions):
return True
return False
- postinstall_config = common.ReadFromInputFile(input_file, POSTINSTALL_CONFIG)
- postinstall_config = [
- line for line in postinstall_config.splitlines() if IsInPartialList(line)]
- if postinstall_config:
- postinstall_config = "\n".join(postinstall_config)
- common.WriteToInputFile(input_file, POSTINSTALL_CONFIG, postinstall_config)
- else:
- os.unlink(os.path.join(input_file, POSTINSTALL_CONFIG))
+ if common.DoesInputFileContain(input_file, POSTINSTALL_CONFIG):
+ postinstall_config = common.ReadFromInputFile(
+ input_file, POSTINSTALL_CONFIG)
+ postinstall_config = [
+ line for line in postinstall_config.splitlines() if IsInPartialList(line)]
+ if postinstall_config:
+ postinstall_config = "\n".join(postinstall_config)
+ common.WriteToInputFile(
+ input_file, POSTINSTALL_CONFIG, postinstall_config)
+ else:
+ os.unlink(os.path.join(input_file, POSTINSTALL_CONFIG))
return input_file