Skip to content

Commit

Permalink
#118 Handle case when zip file is less than 22kb
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed Dec 18, 2019
1 parent 1001f91 commit 156e51a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/net/lingala/zip4j/headers/HeaderReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public class HeaderReader {
private byte[] intBuff = new byte[4];

public ZipModel readAllHeaders(RandomAccessFile zip4jRaf, Charset charset) throws IOException {

if (zip4jRaf.length() < ENDHDR) {
throw new ZipException("Zip file size less than minimum expected zip file size. " +
"Probably not a zip file or a corrupted zip file");
}

zipModel = new ZipModel();

try {
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/net/lingala/zip4j/ExtractZipFileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ public void testExtractNestedZipFileWithAesOnInnerAndZipStandardOuter() throws I
testExtractNestedZipFileWithEncrpytion(EncryptionMethod.AES, EncryptionMethod.ZIP_STANDARD);
}

@Test
public void testExtractZipFileLessThanMinimumExpectedZipFileSizeThrowsException() throws IOException {
expectedException.expect(ZipException.class);
expectedException.expectMessage("Zip file size less than minimum expected zip file size. " +
"Probably not a zip file or a corrupted zip file");

ZipFile zipFile = new ZipFile(getTestArchiveFromResources("invalid_zip_file_size_less_than_22kb.zip"));
zipFile.extractAll(temporaryFolder.toString());
}

private void testExtractNestedZipFileWithEncrpytion(EncryptionMethod innerZipEncryption,
EncryptionMethod outerZipEncryption) throws IOException {
File innerZipFile = temporaryFolder.newFile("inner.zip");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=18.3.0

0 comments on commit 156e51a

Please sign in to comment.