From 39b8f9fc7dc54639e94e3fc146f8efa5ca5eb758 Mon Sep 17 00:00:00 2001 From: Baligh Uddin Date: Sun, 25 Aug 2019 12:01:44 -0700 Subject: [PATCH] DO NOT MERGE - Add a guard against deleting AVB_PUBKey. The avb_pubkey may not be present, if the apex was initially unsigned or generated from a bundle. In this case, running sign_apex to generate a signed apex binary would result in an error. This fix checks for presense of avbpubkey before attempting the deletion BUG: 139994107 Change-Id: I3cb2e88a11ad8797e38ba5fb98c96a4ec4135fc8 --- tools/releasetools/apex_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/releasetools/apex_utils.py b/tools/releasetools/apex_utils.py index fb4ca7667f..66715ca24c 100644 --- a/tools/releasetools/apex_utils.py +++ b/tools/releasetools/apex_utils.py @@ -177,6 +177,7 @@ def SignApex(apex_data, payload_key, container_key, container_pw, payload_dir = common.MakeTempDir(prefix='apex-payload-') with zipfile.ZipFile(apex_file) as apex_fd: payload_file = apex_fd.extract(APEX_PAYLOAD_IMAGE, payload_dir) + zip_items = apex_fd.namelist() payload_info = ParseApexPayloadInfo(payload_file) SignApexPayload( @@ -191,7 +192,8 @@ def SignApex(apex_data, payload_key, container_key, container_pw, payload_public_key = common.ExtractAvbPublicKey(payload_key) common.ZipDelete(apex_file, APEX_PAYLOAD_IMAGE) - common.ZipDelete(apex_file, APEX_PUBKEY) + if APEX_PUBKEY in zip_items: + common.ZipDelete(apex_file, APEX_PUBKEY) apex_zip = zipfile.ZipFile(apex_file, 'a') common.ZipWrite(apex_zip, payload_file, arcname=APEX_PAYLOAD_IMAGE) common.ZipWrite(apex_zip, payload_public_key, arcname=APEX_PUBKEY)