zip4j
zip4j copied to clipboard
Some files in the encrypted zip is extracted, while others showing wrong password
Hi Srikanth, Observing few files is getting extracted and other files showing wrong password while extracting. using 7-Zip to extract the zip file.
Was the zip file generated using zip4j? Which version of zip4j are you using? Can you attach a sample zip file?
Was the zip file generated using zip4j? Yes Srikanth, zip file is created with zip4j only.
Which version of zip4j are you using? using zip4j 2.7.0 version
Can you attach a sample zip file? Sorry, I can't share that zip file. but for reference, I am sharing the screenshot error I am getting. Along with the code logic for zipping.
private void doProtectedZip(ArrayList<File> filesToAdd, String mFileName, String password){ ZipParameters zipParameters = new ZipParameters(); zipParameters.setEncryptFiles(true); zipParameters.setEncryptionMethod(EncryptionMethod.ZIP_STANDARD); File file; ZipFile zipFile = null; try { zipFile = new ZipFile(mFileName,password.toCharArray()); zipFile.addFiles(filesToAdd,zipParameters);
} catch (ZipException e) {
e.printStackTrace();
}
}
It is hard to say what is going wrong without the zip file (although I totally understand that you can't attach it here). Can you please try with the latest version of zip4j to see if that helps? Maybe this issue was resolved in some other bug fix?
Hi Srikanth, Please check with below zip file. Meanwhile I will check with latest version.
Did trying with the new version help?
Hi Srikanth, I tried with latest version as well still issue observing. currently using version 2.7.0 and latest version used 2.9.0
I think you deleted the zip file, right? I did not download it yet
Got it
@HarishKumar7 When you tried with the new version, did you just extract with it or also created the zip file with it? The issue was in creation of the zip file. If you just tried extracting with the newer version of zip4j, please also try creating the zip file with the newer version, because as mentioned earlier, the issue was during the creation of the zip file.
Hi Srikanth, zip creation code I mentioned in the comments. whatever the parameters we are passing is just files Array list, file name and password as string. Does any modification required while creating please suggest. private void doProtectedZip(ArrayList filesToAdd, String mFileName, String password){ ZipParameters zipParameters = new ZipParameters(); zipParameters.setEncryptFiles(true); zipParameters.setEncryptionMethod(EncryptionMethod.ZIP_STANDARD); File file; ZipFile zipFile = null; try { zipFile = new ZipFile(mFileName,password.toCharArray()); zipFile.addFiles(filesToAdd,zipParameters); zipFile.renameFile("XYZ.db","ABC.db"); zipFile.renameFile("RST.db","DEF.db"); } catch (ZipException e) { e.printStackTrace(); } }
Your code looks fine. Please make sure to use the new version of zip4j and see if this happens again.
Hi Srikanth, Same issue with latest version "2.9.0" as well.
@HarishKumar7 Do you see this issue each time you run your code or does it happen randomly? If it is a random issue, approximately how often you see that issue?
Does this issue happen also when you do not rename files? (These lines: zipFile.renameFile("XYZ.db","ABC.db"); zipFile.renameFile("RST.db","DEF.db");
Can you please check if you get this exception also with the below code? If you intend to use this code in production, please test it first. Especially when those db files that you are renaming are within a folder.
private void doProtectedZip(ArrayList<File> filesToAdd, String mFileName, String password) throws ZipException {
ZipParameters zipParameters = new ZipParameters();
zipParameters.setEncryptFiles(true);
zipParameters.setEncryptionMethod(EncryptionMethod.ZIP_STANDARD);
File file;
ZipFile zipFile = null;
try {
zipFile = new ZipFile(mFileName,password.toCharArray());
for (File fileToAdd : filesToAdd) {
if (fileToAdd.getName().equals("XYZ.db")) {
zipParameters.setFileNameInZip("ABC.db");
} else if (fileToAdd.getName().equals("RST.db")) {
zipParameters.setFileNameInZip("DEF.db");
} else {
zipParameters.setFileNameInZip(null);
}
zipFile.addFile(fileToAdd, zipParameters);
}
} catch (ZipException e) {
e.printStackTrace();
}
}
@HarishKumar7 Do you have any regarding the comment above?
Hi Srikanth, I have the same problem, I already comment it in other issues https://github.com/srikanth-lingala/zip4j/issues/342#issuecomment-901556399
I'm using latest version, it rarely happened (maybe 1%), I didn't rename files. We are using zip4j about 1 year from version 2.6.4 and 2.7.0 and didn't see any issue reported from client, last 2 month, we upgrade library to 2.9.0 and we received reported about this issue. However, Harish have problem on 2.7.0 so it may not a problem with 2.9.0
Same issue, I'm using java 11 and I've tried versions from 2.3 to 2.9. None of them allowed me successfully add a password to my Zip. It is generated, but once I open it I don't have to put any password to uncompress it
@PhanVanLinh This will be a tricky one to investigate considering the fact that it is so rarely reproducible. I will try running the code in loop and verifying. I already did that once, but I will try again. If I understood right, you are just adding files to zip, and very rarely, the password is not set to a file in zip, right?
@saulgiordani Your issue sounds like you are not able to set a password to an entry in zip each time, right? Or does it also happen randomly for you? i.e, most of the times it works, and sometimes rarely it doesn't