codemagic-ci-cd / cli-tools

Various utilities to managing Android and iOS app builds, code signing, and deployment.
https://codemagic.io/start/
GNU General Public License v3.0
243 stars 42 forks source link

Add support for large iOS application packages #342

Closed priitlatt closed 1 year ago

priitlatt commented 1 year ago

Creating Ipa instances from large archives (4+GB) results in the following exception:

Traceback (most recent call last):
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/models/application_package/ipa.py", line 23, in _validate_package
    return bool(self.info_plist)
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/models/application_package/ipa.py", line 83, in info_plist
    return self._get_info_plist()
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/models/application_package/ipa.py", line 77, in _get_info_plist
    info_plist_contents = self._get_app_file_contents("Info.plist")
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/models/application_package/ipa.py", line 57, in _get_app_file_contents
    return self._extract_file(filename_filter)
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/site-packages/codemagic/models/application_package/ipa.py", line 35, in _extract_file
    with zf.open(found_file_name, "r") as fd:
  File "/Users/builder/.pyenv/versions/3.8.13/lib/python3.8/zipfile.py", line 1532, in open
    raise BadZipFile("Truncated file header")
zipfile.BadZipFile: Truncated file header

Similar error occurs when unzip is used:

$ unzip -p app.ipa Payload/Runner.app/Info.plist
warning [app.ipa]:  17179869184 extra bytes at beginning or within zipfile
  (attempting to process anyway)
file #1:  bad zipfile offset (lseek):  17362427904

This is because macOS creates corrupt zip archives when the file size exceeds 4GB (more information on the matter can be read from this SO answer: https://stackoverflow.com/a/59518097). 7-Zip is capable of handling such archives and this PR adds a fallback to use 7z in case zipfile.BadZipFile: Truncated file header error is encountered.