From b789e844990a3549844a7baee6bd67a5b9bf7e4a Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Tue, 13 Jun 2023 10:34:32 -0700 Subject: [PATCH 1/2] Search for partition maps in IMAGES dir as well Partition images are allowed to be in either IMAGES/ or RADIO/ dir of a target_files zip, so when searching for .map files we should look in both dirs. Test: th Bug: 227848550 Change-Id: I0a9d2c582d8f5d570237434902fac012513c9aad --- tools/releasetools/ota_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/releasetools/ota_utils.py b/tools/releasetools/ota_utils.py index 466cafb1cb..68c6887f87 100644 --- a/tools/releasetools/ota_utils.py +++ b/tools/releasetools/ota_utils.py @@ -760,6 +760,9 @@ def GetPartitionImages(target_files_dir: str, ab_partitions, allow_empty=True): def LocatePartitionMap(target_files_dir: str, partition: str): path = os.path.join(target_files_dir, "RADIO", partition + ".map") + if os.path.exists(path): + return path + path = os.path.join(target_files_dir, "IMAGES", partition + ".map") if os.path.exists(path): return path return "" From 38d0c373ac9e0f00c6e677c41bbc85f0e364ba02 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Wed, 14 Jun 2023 12:53:29 -0700 Subject: [PATCH 2/2] Fix python3.11's support for zip64 Bug: 283033491 Test: check_target_files_signatures -v -l Change-Id: I9c1a5346e3a5f3920242dc9a5268d999f50a4937 --- tools/releasetools/common.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index f92d67cee1..d33397b9a3 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -2126,17 +2126,28 @@ def UnzipToDir(filename, dirname, patterns=None): """ with zipfile.ZipFile(filename, allowZip64=True, mode="r") as input_zip: # Filter out non-matching patterns. unzip will complain otherwise. + entries = input_zip.infolist() + # b/283033491 + # Per https://en.wikipedia.org/wiki/ZIP_(file_format)#Central_directory_file_header + # In zip64 mode, central directory record's header_offset field might be + # set to 0xFFFFFFFF if header offset is > 2^32. In this case, the extra + # fields will contain an 8 byte little endian integer at offset 20 + # 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. + 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 patterns is not None: - names = input_zip.namelist() - filtered = [name for name in names if any( - [fnmatch.fnmatch(name, p) for p in patterns])] + filtered = [info for info in entries if any( + [fnmatch.fnmatch(info.filename, p) for p in patterns])] # There isn't any matching files. Don't unzip anything. if not filtered: return input_zip.extractall(dirname, filtered) else: - input_zip.extractall(dirname) + input_zip.extractall(dirname, entries) def UnzipTemp(filename, patterns=None):