From dc81e8571f9bef7d679e8df184673ac80b651dbd Mon Sep 17 00:00:00 2001 From: Andrew Gunnerson Date: Mon, 22 May 2023 23:39:54 -0400 Subject: [PATCH] Strip out 0xd935 extra field record in zip entries The extra field record was previously stripped out due to a bug in Python's zipfile implementation. That was fixed by [1], which was backported to 3.10 and 3.11, but not 3.9. This commit explicitly strips out the 0xd935 record to ensure that the checksums of the patched files are the same across all Python versions. This is probably the correct thing to do anyway, since the record is related to zip entry alignment [2], which we don't do. Note that the Python bug can affect other extra field records too, but we don't see that in practice. [1] https://github.com/python/cpython/commit/62c0327487ce39ec6504919b7712e0f197075ef9 [2] https://android.googlesource.com/platform/build/+/android-13.0.0_r1/tools/signapk/src/com/android/signapk/SignApk.java#133 Fixes: #93 Signed-off-by: Andrew Gunnerson --- avbroot/main.py | 25 +++++++++++++++++++++++-- tests/tests.yaml | 4 ++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/avbroot/main.py b/avbroot/main.py index 8e5b28b..ba221bb 100644 --- a/avbroot/main.py +++ b/avbroot/main.py @@ -4,6 +4,7 @@ import copy import io import os import shutil +import struct import tempfile import time import zipfile @@ -150,6 +151,25 @@ def patch_ota_payload(f_in, open_more_f_in, f_out, file_size, boot_partition, ) +def strip_alignment_extra_field(extra): + offset = 0 + new_extra = bytearray() + + while offset < len(extra): + record_sig, record_len = \ + struct.unpack('