zeroturnaround / zt-zip

ZeroTurnaround ZIP Library
http://www.zeroturnaround.com/
Apache License 2.0
1.38k stars 251 forks source link

Can not unpack zip with original structure #69

Closed hfzzztz closed 8 years ago

hfzzztz commented 9 years ago

Version 1.7 When I unpacking a zip file containing folders in Linux, all the entries in the zip are unpacked with name containing it's parent folders' names. Folders are omitted. But on windows everything is fine. Even on Linux some zip file can be unpacked correctly, while some can not. Is anything wrong? Thanks for your help.

Structure of zip image

Entries unpacked image

toomasr commented 9 years ago

Can you share the code you use to unpack archives with zt-zip?

hfzzztz commented 9 years ago

I use this API to unpack zip file. public static void unpack(InputStream is, File outputDir) in ZipUtil

/* * Returns true if this is a directory entry. A directory entry is * defined to be one whose name ends with a '/'. * @return true if this is a directory entry / public boolean isDirectory() { return name.endsWith("/"); }

I think I find the reason now. As you can see, zipUtil use ‘/’ as separator. But some zip file use '\' as separator.

toomasr commented 9 years ago

Yup, that could cause this. I'll try to create some zip archives and see from there.

toomasr commented 9 years ago

Based on the Zip specification ( https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT ) everything must be forward slash. Can you share an archive that produces the problems you are having?

hfzzztz commented 9 years ago

I am sorry that I can not share these archives for these archives may contain confidential information. But these archives are produced on windows using File.separator that is '\' as separator. Thanks for your help.

toomasr commented 9 years ago

Can you create an archive that has the \ in it that you can share? I tried with Windows compression to get the archive that wouldn't work but I couldn't.

hfzzztz commented 9 years ago

I might confused you. The archive that wouldn't work was created by another program, not zt-zip. That program use File.separator as separator. zt-zip does not. At first I doubt if there is anything wrong with zip unpacking functionality. But now I think it is not zt-zip's bug.

toomasr commented 9 years ago

I think I do understand. The spec says that the only separator should be a forward slash (/) but some software out there also creates with a separator that is a backslash ().

zt-zip will never start creating these archives. If there are enough of these wrong archives on the internet then we can add support to unpacking these BUT I haven't found such archives yet.

hfzzztz commented 9 years ago

I create a zip taking '\' as separator. On Windows this zip can be unpack correctly because Windows takes '\' as separator too. Here is the result I unpacked on Linux. image I send the zip file to your email.

toomasr commented 9 years ago

Thank you for providing the test archive. I did some work on the library on Friday. I added a BackslashUnpacker. You can see the usage at https://github.com/zeroturnaround/zt-zip/blob/master/src/test/java/org/zeroturnaround/zip/ZipUtilTest.java#L847 Let me know if this fixes the issue for you.

nemecec commented 8 years ago

zt-zip 1.9 has been released, containing the above mentioned improvements.