Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98145fb7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Revert "Remove all ZIP64LIMIT hack"" am: 7b640806 am: 78667a46 am: 4fdafe37

parents 2009c248 4fdafe37
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -842,13 +842,14 @@ def ReplaceUpdatedFiles(zip_filename, files_list):
  SYSTEM/ after rebuilding recovery.
  """
  common.ZipDelete(zip_filename, files_list)
  with zipfile.ZipFile(zip_filename, "a",
  output_zip = zipfile.ZipFile(zip_filename, "a",
                               compression=zipfile.ZIP_DEFLATED,
                               allowZip64=True) as output_zip:
                               allowZip64=True)
  for item in files_list:
    file_path = os.path.join(OPTIONS.input_tmp, item)
    assert os.path.exists(file_path)
    common.ZipWrite(output_zip, file_path, arcname=item)
  common.ZipClose(output_zip)


def HasPartition(partition_name):
@@ -1191,7 +1192,7 @@ def AddImagesToTargetFiles(filename):
  AddVbmetaDigest(output_zip)

  if output_zip:
    output_zip.close()
    common.ZipClose(output_zip)
    if OPTIONS.replace_updated_files_list:
      ReplaceUpdatedFiles(output_zip.filename,
                          OPTIONS.replace_updated_files_list)
+1 −1
Original line number Diff line number Diff line
@@ -431,7 +431,7 @@ def SignUncompressedApex(avbtool, apex_file, payload_key, container_key,
  apex_zip = zipfile.ZipFile(apex_file, 'a', allowZip64=True)
  common.ZipWrite(apex_zip, payload_file, arcname=APEX_PAYLOAD_IMAGE)
  common.ZipWrite(apex_zip, payload_public_key, arcname=APEX_PUBKEY)
  apex_zip.close()
  common.ZipClose(apex_zip)

  # 3. Sign the APEX container with container_key.
  signed_apex = common.MakeTempFile(prefix='apex-container-', suffix='.apex')
+2 −2
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ def VerifyAbOtaPayload(cert, package):
  """Verifies the payload and metadata signatures in an A/B OTA payload."""
  package_zip = zipfile.ZipFile(package, 'r', allowZip64=True)
  if 'payload.bin' not in package_zip.namelist():
    package_zip.close()
    common.ZipClose(package_zip)
    return

  print('Verifying A/B OTA payload signatures...')
@@ -160,7 +160,7 @@ def VerifyAbOtaPayload(cert, package):
         '--in_file=' + payload_file,
         '--public_key=' + pubkey]
  common.RunAndCheckOutput(cmd)
  package_zip.close()
  common.ZipClose(package_zip)

  # Verified successfully upon reaching here.
  print('\nPayload signatures VERIFIED\n\n')
+30 −1
Original line number Diff line number Diff line
@@ -2819,6 +2819,18 @@ class PasswordManager(object):
def ZipWrite(zip_file, filename, arcname=None, perms=0o644,
             compress_type=None):

  # http://b/18015246
  # Python 2.7's zipfile implementation wrongly thinks that zip64 is required
  # for files larger than 2GiB. We can work around this by adjusting their
  # limit. Note that `zipfile.writestr()` will not work for strings larger than
  # 2GiB. The Python interpreter sometimes rejects strings that large (though
  # it isn't clear to me exactly what circumstances cause this).
  # `zipfile.write()` must be used directly to work around this.
  #
  # This mess can be avoided if we port to python3.
  saved_zip64_limit = zipfile.ZIP64_LIMIT
  zipfile.ZIP64_LIMIT = (1 << 32) - 1

  if compress_type is None:
    compress_type = zip_file.compression
  if arcname is None:
@@ -2844,13 +2856,14 @@ def ZipWrite(zip_file, filename, arcname=None, perms=0o644,
  finally:
    os.chmod(filename, saved_stat.st_mode)
    os.utime(filename, (saved_stat.st_atime, saved_stat.st_mtime))
    zipfile.ZIP64_LIMIT = saved_zip64_limit


def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=None,
                compress_type=None):
  """Wrap zipfile.writestr() function to work around the zip64 limit.

  Python's zip implementation won't allow writing a string
  Even with the ZIP64_LIMIT workaround, it won't allow writing a string
  longer than 2GiB. It gives 'OverflowError: size does not fit in an int'
  when calling crc32(bytes).

@@ -2859,6 +2872,9 @@ def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=None,
  when we know the string won't be too long.
  """

  saved_zip64_limit = zipfile.ZIP64_LIMIT
  zipfile.ZIP64_LIMIT = (1 << 32) - 1

  if not isinstance(zinfo_or_arcname, zipfile.ZipInfo):
    zinfo = zipfile.ZipInfo(filename=zinfo_or_arcname)
    zinfo.compress_type = zip_file.compression
@@ -2891,6 +2907,7 @@ def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=None,
  zinfo.date_time = (2009, 1, 1, 0, 0, 0)

  zip_file.writestr(zinfo, data)
  zipfile.ZIP64_LIMIT = saved_zip64_limit


def ZipDelete(zip_filename, entries, force=False):
@@ -2923,6 +2940,18 @@ def ZipDelete(zip_filename, entries, force=False):
  os.replace(new_zipfile, zip_filename)


def ZipClose(zip_file):
  # http://b/18015246
  # zipfile also refers to ZIP64_LIMIT during close() when it writes out the
  # central directory.
  saved_zip64_limit = zipfile.ZIP64_LIMIT
  zipfile.ZIP64_LIMIT = (1 << 32) - 1

  zip_file.close()

  zipfile.ZIP64_LIMIT = saved_zip64_limit


class DeviceSpecificParams(object):
  module = None

+2 −2
Original line number Diff line number Diff line
@@ -272,7 +272,7 @@ endif;

  # We haven't written the metadata entry, which will be done in
  # FinalizeMetadata.
  output_zip.close()
  common.ZipClose(output_zip)

  needed_property_files = (
      NonAbOtaPropertyFiles(),
@@ -526,7 +526,7 @@ endif;

  # We haven't written the metadata entry yet, which will be handled in
  # FinalizeMetadata().
  output_zip.close()
  common.ZipClose(output_zip)

  # Sign the generated zip package unless no_signing is specified.
  needed_property_files = (
Loading