Skip to content

Commit

Permalink
#373 Fill NPE when aesKeyStrength is null
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed Mar 13, 2022
1 parent 66dc565 commit 35122fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ private byte[] getSalt(LocalFileHeader localFileHeader) throws IOException {
}

AESExtraDataRecord aesExtraDataRecord = localFileHeader.getAesExtraDataRecord();

if (aesExtraDataRecord.getAesKeyStrength() == null) {
throw new IOException("Invalid aes key strength in aes extra data record");
}

byte[] saltBytes = new byte[aesExtraDataRecord.getAesKeyStrength().getSaltLength()];
readRaw(saltBytes);
return saltBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ public void testExtractZipFileWithDirectoriesContainingExtendedLocalFileHeader()
null, InternalZipConstants.BUFF_SIZE, false, 2);
}

@Test
public void testExtractZipFileWithNullAesExtraDataRecordThrowsException() throws IOException {
expectedException.expect(IOException.class);
expectedException.expectMessage("Invalid aes key strength in aes extra data record");

extractZipFileWithInputStreams(TestUtils.getTestArchiveFromResources("null-aes-key-strength-in-aes-extra-data-record"),
null, InternalZipConstants.BUFF_SIZE, false, 1);
}

private void extractZipFileWithInputStreams(File zipFile, char[] password) throws IOException {
extractZipFileWithInputStreams(zipFile, password, InternalZipConstants.BUFF_SIZE);
}
Expand Down
Binary file not shown.

0 comments on commit 35122fd

Please sign in to comment.