srikanth-lingala / zip4j

A Java library for zip files and streams
Apache License 2.0
2.06k stars 310 forks source link

Unable to unpack an archive created on linux #411

Open Szymon1998 opened 2 years ago

Szymon1998 commented 2 years ago

Hi, I have got a problem with zip4j above 2.0 version. Durning using linux Centos7 the archive after compress with AES encritpion can't be unpacked. (whole code belowe) 7zip - doesn't show password input popup. Shows 'error about headers', 'unconfirmed archive start' and warning about data behind end block of usable data. WinRAR - after put correct password shows error: 'Wrong password'

ZipParameters parameters = new ZipParameters();

parameters.setCompressionMethod(CompressionMethod.STORE);
parameters.setEncryptFiles(true);

parameters.setEncryptionMethod(EncryptionMethod.AES);
parameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_256);

ZipFile zipFile = new ZipFile(dir_path + '/' + zipName, password.toCharArray());

zipFile.addFiles(filesToAdd, parameters);
srikanth-lingala commented 2 years ago

Hi, I don't have access to a Centos to try this out. I will try to setup a VM with Centos but that will take a while for me to get to.

Do you get the same error if you use CompressionMethod.DEFLATE as the compression method instead of CompressionMethod.STORE? And also, can you attach a sample zip file which has this issue?

Szymon1998 commented 2 years ago

Yes, CompressionMethod doesn't matter. Zip file in attachments. Password: "demo12345" new.zip

srikanth-lingala commented 2 years ago

I have got a problem with zip4j above 2.0 version.

BTW, to be precise, which version of zip4j are you using?

Szymon1998 commented 2 years ago

I used 2.9.1. The highest version I use without these issues is 1.3.3

srikanth-lingala commented 2 years ago

Strangely, on my mac I am able to extract your zip file with inbuilt zip utility, and also with the app called "The Unarchiver". But Keka, which uses 7zip in the background cannot extract the zip file.

What makes investigating this issue hard is that I don't have access to Centos unfortunately. I tried installing VirtualBox and install an image of Centos, but that went horribly wrong and I got a lot of errors. Unfortunately without being able to reproduce the issue, I can't really say what is going wrong here.

I will however try looking at the zip metadata and try to deduce if some header is being wrongly written. I believe this issue is because of the fact that different tools rely on different parts of zip's metadata to retrieve the same information.