Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullpointer exception with empty file name in ZipParameters #388

Closed
pdenooijer opened this issue Nov 30, 2021 · 2 comments
Closed

Nullpointer exception with empty file name in ZipParameters #388

pdenooijer opened this issue Nov 30, 2021 · 2 comments
Assignees
Labels
bug Something isn't working resolved

Comments

@pdenooijer
Copy link

pdenooijer commented Nov 30, 2021

Since this change from version 2.9.0 tot 2.9.1 the file name could still be null leading to a null pointer exception.

The validation is done in the FileHeaderFactory, but this is called from the initializeAndWriteFileHeader. As this is now after the directory check, this will never trigger:

  private String validateAndGetFileName(String fileNameInZip) throws ZipException {
    if (!Zip4jUtil.isStringNotNullAndNotEmpty(fileNameInZip)) {
      throw new ZipException("fileNameInZip is null or empty");
    } else {
      return fileNameInZip;
    }
  }

Problematic code, 2e line is the problem when file name is null:

ZipParameters clonedZipParameters = new ZipParameters(zipParameters);
if (isZipEntryDirectory(zipParameters.getFileNameInZip())) {
  clonedZipParameters.setWriteExtendedLocalFileHeader(false);
  clonedZipParameters.setCompressionMethod(CompressionMethod.STORE);
  clonedZipParameters.setEncryptFiles(false);
}
initializeAndWriteFileHeader(clonedZipParameters);

There are multiple solutions to solve this. Moving the validation to an earlier point or making sure there is no null pointer exception by checking if it's not null.

@srikanth-lingala
Copy link
Owner

Thanks for the elaborate writeup @pdenooijer. I will fix it.

iinegve added a commit to iinegve/zip4j that referenced this issue Feb 20, 2022
@srikanth-lingala srikanth-lingala added bug Something isn't working resolved labels Mar 23, 2022
@srikanth-lingala srikanth-lingala self-assigned this Mar 23, 2022
@srikanth-lingala
Copy link
Owner

Fixed in v2.10.0 released today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved
Projects
None yet
Development

No branches or pull requests

2 participants