Skip to content

speed-up replicateZip - reduce CPU utilization and fix ZIP format errors#506

Open
jpstotz wants to merge 1 commit into
majd:mainfrom
jpstotz:replicateZip
Open

speed-up replicateZip - reduce CPU utilization and fix ZIP format errors#506
jpstotz wants to merge 1 commit into
majd:mainfrom
jpstotz:replicateZip

Conversation

@jpstotz

@jpstotz jpstotz commented Jul 2, 2026

Copy link
Copy Markdown

In the step ReplicateSinf ipatool creates a new temporary file for adding the sinf data.

To do so it reads and decompresses every entry of the downloaded ipa file and then recompresses and writes it to the newly created temp zip file.

This has two disadvantages:

  1. it costs a lot of CPU considering that some apps in app store have a size of 2Gb and more
  2. It re-creates the ZIP header data for every ZIP file entry and causes errors in the ZIP structure e.g. it creates EXT descriptors for DEFLATED entries which as far as I know violates the ZIP spec (some zip streaming reader throw an error like only DEFLATED entries can have EXT descriptor. Just copying the ZIP header and data from the original data Apple provides does not have this problem.

The small path for replicateZip I propose in this PR fixes both problems:

Using OpenRaw() and CreateRaw() instead of Open() and CreateHeader() keeps the existing compressed entry bytes intact and avoids decompressing/recompressing during the SINF rewrite, while still preserving the original file header metadata carried by FileHeader.

I tested the patched version with several apps. The downloaded ipa file is slightly smaller that the one created with ipatool before the patch. I tested the downloaded IPA files with several ZIP tools (7-zip, winrar, unzip, ..) and they all say "no errors detected" when testing the IPA files downloaded by the modified ipatool version.

In addition the downloaded ipa files could successfully be installed on a non-jailbroken iPhone running iOS 18.


Summary by cubic

Speeds up SINF replication by streaming raw compressed ZIP entries via OpenRaw/CreateRaw instead of decompressing/recompressing. This cuts CPU usage for large IPAs.

  • Bug Fixes
    • Preserves original ZIP headers to avoid invalid EXT descriptors on DEFLATED entries and related structural errors.
    • Outputs slightly smaller IPAs that validate with common ZIP tools and install on iOS 18.

Written for commit 4a53e91. Summary will update on new commits.

Review in cubic

@jpstotz jpstotz changed the title speed-up replicateZip - reduce CPU utilization when downloading speed-up replicateZip - reduce CPU utilization and fix ZIP format errors Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant