Skip to content

Commit

Permalink
Remove python2-specific ApplyZipFileZipAlignFix()
Browse files Browse the repository at this point in the history
Relevant scripts are python3 now :)

Change-Id: Iec169510eb359b1803c73b12c0615e0b247b2838
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3868107
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Peter Wen <wnwen@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1042163}
  • Loading branch information
agrieve authored and Chromium LUCI CQ committed Sep 1, 2022
1 parent df7332f commit 77d6bab
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 59 deletions.
3 changes: 0 additions & 3 deletions build/android/gyp/apkbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
from util import diff_utils
from util import zipalign

# Input dex.jar files are zipaligned.
zipalign.ApplyZipFileZipAlignFix()


# Taken from aapt's Package.cpp:
_NO_COMPRESS_EXTENSIONS = ('.jpg', '.jpeg', '.png', '.gif', '.wav', '.mp2',
Expand Down
52 changes: 0 additions & 52 deletions build/android/gyp/util/zipalign.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import struct
import sys
import zipfile

from util import build_utils

_FIXED_ZIP_HEADER_LEN = 30


def _PatchedDecodeExtra(self):
# Try to decode the extra field.
extra = self.extra
unpack = struct.unpack
while len(extra) >= 4:
tp, ln = unpack('<HH', extra[:4])
if tp == 1:
if ln >= 24:
counts = unpack('<QQQ', extra[4:28])
elif ln == 16:
counts = unpack('<QQ', extra[4:20])
elif ln == 8:
counts = unpack('<Q', extra[4:12])
elif ln == 0:
counts = ()
else:
raise RuntimeError("Corrupt extra field %s" % (ln, ))

idx = 0

# ZIP64 extension (large files and/or large archives)
if self.file_size in (0xffffffffffffffff, 0xffffffff):
self.file_size = counts[idx]
idx += 1

if self.compress_size == 0xffffffff:
self.compress_size = counts[idx]
idx += 1

if self.header_offset == 0xffffffff:
self.header_offset = counts[idx]
idx += 1

extra = extra[ln + 4:]


def ApplyZipFileZipAlignFix():
"""Fix zipfile.ZipFile() to be able to open zipaligned .zip files.
Android's zip alignment uses not-quite-valid zip headers to perform alignment.
Python < 3.4 crashes when trying to load them.
https://bugs.python.org/issue14315
"""
if sys.version_info < (3, 4):
zipfile.ZipInfo._decodeExtra = ( # pylint: disable=protected-access
_PatchedDecodeExtra)


def _SetAlignment(zip_obj, zip_info, alignment):
"""Sets a ZipInfo's extra field such that the file will be aligned.
Expand Down
3 changes: 0 additions & 3 deletions build/android/resource_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,11 @@

with host_paths.SysPath(_ANDROID_UTILS_PATH, 0):
from util import build_utils # pylint: disable=import-error
from util import zipalign # pylint: disable=import-error

with host_paths.SysPath(_BUILD_UTILS_PATH, 0):
from lib.results import result_sink # pylint: disable=import-error
from lib.results import result_types # pylint: disable=import-error

zipalign.ApplyZipFileZipAlignFix()

# Captures an entire config from aapt output.
_AAPT_CONFIG_PATTERN = r'config %s:(.*?)config [a-zA-Z-]+:'
# Matches string resource entries from aapt output.
Expand Down
1 change: 0 additions & 1 deletion build/android/resource_sizes.pydeps
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
devil_chromium.py
gyp/util/__init__.py
gyp/util/build_utils.py
gyp/util/zipalign.py
method_count.py
pylib/__init__.py
pylib/constants/__init__.py
Expand Down

0 comments on commit 77d6bab

Please sign in to comment.