"Illegal byte sequence" when using unzip on macOS High Sierra to extract a file with Cyrillic characters #250

Open
opened 2026-01-29 22:08:59 +00:00 by claunia · 10 comments
Owner

Originally created by @alex-swiftify on GitHub (Oct 24, 2017).

When trying to extract repacked.zip (created with SharpCompress)
with macOS unzip (UnZip 6.00 of 20 April 2009, by Info-ZIP), the file with cyrillic characters in its name (Векторный смарт-объект-3.png) fails to extract:

MacBook-Pro-Alex:_ alex$ unzip repacked.zip 
Archive:  repacked.zip
error:  cannot create icredible_mockAPI_version/ICredible/Assets.xcassets/Images/who_rated_me.imageset/??????????????? ???+?????-?????????-3.png
        Illegal byte sequence

The original zip archive containing the same file (likely compressed with macOS "Archive Utility")
original.zip extracts with unzip just fine.

This problem appeared since I have upgraded to macOS High Sierra (= was not present on macOS Sierra).
Is there anything we can do with the file encoding (i.e. use Unicode) to have it properly unzipped by macOS unzip?

Originally created by @alex-swiftify on GitHub (Oct 24, 2017). When trying to extract [repacked.zip](https://github.com/adamhathcock/sharpcompress/files/1411764/repacked.zip) (created with SharpCompress) with macOS `unzip` (UnZip 6.00 of 20 April 2009, by Info-ZIP), the file with cyrillic characters in its name (`Векторный смарт-объект-3.png`) fails to extract: ``` MacBook-Pro-Alex:_ alex$ unzip repacked.zip Archive: repacked.zip error: cannot create icredible_mockAPI_version/ICredible/Assets.xcassets/Images/who_rated_me.imageset/??????????????? ???+?????-?????????-3.png Illegal byte sequence ``` The original zip archive containing the same file (likely compressed with macOS "Archive Utility") [original.zip](https://github.com/adamhathcock/sharpcompress/files/1411763/original.zip) extracts with `unzip` just fine. This problem appeared since I have upgraded to macOS High Sierra (= was not present on macOS Sierra). Is there anything we can do with the file encoding (i.e. use Unicode) to have it properly unzipped by macOS `unzip`?
Author
Owner

@adamhathcock commented on GitHub (Oct 25, 2017):

There is the ArchiveEncoding that is defaulting to UTF8. I should revisit the spec to see about flagging more encoding if that's possible.

It's likely all of zip encoding needs to be revisited. It is odd though that it's only broken with High Sierra. I guess unzip got more strict.

@adamhathcock commented on GitHub (Oct 25, 2017): There is the ArchiveEncoding that is defaulting to UTF8. I should revisit the spec to see about flagging more encoding if that's possible. It's likely all of zip encoding needs to be revisited. It is odd though that it's only broken with High Sierra. I guess `unzip` got more strict.
Author
Owner

@alex-swiftify commented on GitHub (Oct 25, 2017):

There is the ArchiveEncoding that is defaulting to UTF8. I should revisit the spec to see about flagging more encoding if that's possible.

Thanks! Can we currently set the encoding to anything else (i.e. UTF16) without changes to SharpCompress?

It is odd though that it's only broken with High Sierra. I guess unzip got more strict.

Since the "unzip" utility is dated 20 April 2009, I'm pretty sure this is related to upgrade to APFS file system that was introduced in High Sierra.

@alex-swiftify commented on GitHub (Oct 25, 2017): >There is the ArchiveEncoding that is defaulting to UTF8. I should revisit the spec to see about flagging more encoding if that's possible. Thanks! Can we currently set the encoding to anything else (i.e. UTF16) without changes to SharpCompress? >It is odd though that it's only broken with High Sierra. I guess unzip got more strict. Since the "unzip" utility is dated 20 April 2009, I'm pretty sure this is related to upgrade to APFS file system that was introduced in High Sierra.
Author
Owner

@adamhathcock commented on GitHub (Oct 25, 2017):

Yeah you can change the encoding to anything. It's just if unzip understands/expects it or not. The code is only writing out a specific flag for UTF8

@adamhathcock commented on GitHub (Oct 25, 2017): Yeah you can change the encoding to anything. It's just if unzip understands/expects it or not. The code is only writing out a specific flag for UTF8
Author
Owner

@HadrainChen commented on GitHub (May 29, 2018):

Has anyone fix?

@HadrainChen commented on GitHub (May 29, 2018): Has anyone fix?
Author
Owner

@mrietveld commented on GitHub (Jun 17, 2018):

Use open, as in open fileWithUnicodeCharacters.zip. It looks like open will call an internal OS X program that has no problem open these type of .zip files.

@mrietveld commented on GitHub (Jun 17, 2018): Use `open`, as in `open fileWithUnicodeCharacters.zip`. It looks like `open` will call an internal OS X program that has no problem open these type of `.zip` files.
Author
Owner

@alex-swiftify commented on GitHub (Aug 2, 2018):

Replacing unzip utility used in our script with ditto as suggested here fixed the problem.

@alex-swiftify commented on GitHub (Aug 2, 2018): Replacing `unzip` utility used in our script with `ditto` as suggested [here](https://github.com/CocoaPods/CocoaPods/issues/7711) fixed the problem.
Author
Owner

@Jack-ym commented on GitHub (Apr 26, 2019):

I have met the same question,have you had the correct solution?

@Jack-ym commented on GitHub (Apr 26, 2019): I have met the same question,have you had the correct solution?
Author
Owner

@LeSaul commented on GitHub (Feb 17, 2020):

I had the same issue and tried to unzip and open the file through terminal but the quick solution was ask to a workmate that use windows help to expand the file. Maybe the file folder is too long or idk why it's happening. Cross-platform issues?

@LeSaul commented on GitHub (Feb 17, 2020): I had the same issue and tried to unzip and open the file through terminal but the quick solution was ask to a workmate that use windows help to expand the file. Maybe the file folder is too long or idk why it's happening. Cross-platform issues?
Author
Owner

@tatoalo commented on GitHub (Mar 12, 2020):

Just happened to me today.

@LeSaul, instead of relying on a workmate you could maybe use this, worked like a charm.

@tatoalo commented on GitHub (Mar 12, 2020): Just happened to me today. @LeSaul, instead of relying on a workmate you could maybe use [this](https://theunarchiver.com/), worked like a charm.
Author
Owner

@dbogatov commented on GitHub (Jun 24, 2024):

Install latest unzip from brew brew install unzip.

@dbogatov commented on GitHub (Jun 24, 2024): Install latest unzip from brew `brew install unzip`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#250