pixelglow/ZipZap

Creating a zip with a directory inside and then previewing in iOS crashes Quick Look

Closed this issue · 4 comments

AriX commented

Hi there,

Zip files created by ZipZap with directories inside seem to crash on iOS when previewed by Quick Look. See this project for an example (build & run the ZipZapDirectoryTest target). The following is logged to the console:

2016-02-19 01:33:40.343 ZipZapDirectoryTest[729:187096] BOM could not extract archive: Couldn't read pkzip signature.
2016-02-19 01:33:40.344 ZipZapDirectoryTest[729:187096] BOM could not extract archive: Not a central directory signature

A few interesting/strange points of note:

  • Creating a zip with the same contents from Finder in OS X does not exhibit the same issue when the file is previewed on iOS (an example is provided in the aforementioned demo app)
  • If you take the zip file created with ZipZap and extract it under Finder in OS X, it works fine.
  • Strangely, if you skip adding the archive entry provided by -archiveEntryWithDirectoryName:, iOS is able to successfully preview the zip. But, I'm worried that other apps might consider this to be a malformed zip.

Hoping for some guidance here as to why iOS is considering ZipZap's archives to be malformed.

Thanks!
Ari

Good spot!

It looks like a bug in the Quick Look framework, but with a decent workaround. The potential fix will make smaller zip files too.

For each zip entry, ZipZap first writes out the block data, then it writes out compressed size, uncompressed size and CRC in an extra data descriptor. This is allowed by the ZIP file spec and helps support streaming out the file in a single pass. However, this extra descriptor is also written out if there's no blocks to provide data, as with a directory. Apparently Quick Look doesn't expect this and hangs, thinking the zip is corrupt.

The fix is to skip the extra descriptor for no blocks. This also leads to shorter zip files since directories and empty entries don't have to output that descriptor.

I'll code and test a fix, and push it up soon.

AriX commented

Awesome! Thanks so much for the quick action on this. My company would be willing to sponsor development if this could be done in the next couple of days. Let me know if you're interested!

I already donated a bit on ChangeTip, since I really appreciate the work put into this project. But I found ChangeTip a bit cumbersome to use, and it seemed to have a $25 limit.

By the way - since this is a standard format that Quick Look really should handle, I went ahead an filed rdar://24738575 about the issue as well (though I certainly don't expect quick progress from Apple).

Thanks for the offer to sponsor!

You can send bitcoin to 1HUFjghYhvrpCWKAYD4x1ihE3fM4VqNL5H.

Or, I can send out a "request to pay" from PayPal. Tell me how much you want to pay and your email address and I'll send that out.

Given the time spent and the turnaround on this, $200 would be appropriate, but since this is a donation I'll leave it up to you to decide how much.

AriX commented

Fantastic. We'd be happy to contribute $250 for your efforts. PayPal would be ideal if possible - I'll shoot you an email with details.

Thanks!
Ari