Skip to content

Commit

Permalink
#375 Throw exception when file name length is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed Mar 13, 2022
1 parent be95bc3 commit e6c2d13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/lingala/zip4j/headers/HeaderReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private CentralDirectory readCentralDirectory(RandomAccessFile zip4jRaf, RawIO r
String fileName = decodeStringWithCharset(fileNameBuff, fileHeader.isFileNameUTF8Encoded(), charset);
fileHeader.setFileName(fileName);
} else {
fileHeader.setFileName(null);
throw new ZipException("Invalid entry name in file header");
}

fileHeader.setDirectory(isDirectory(fileHeader.getExternalFileAttributes(), fileHeader.getFileName()));
Expand Down Expand Up @@ -558,7 +558,7 @@ public LocalFileHeader readLocalFileHeader(InputStream inputStream, Charset char
localFileHeader.setFileName(fileName);
localFileHeader.setDirectory(fileName.endsWith("/") || fileName.endsWith("\\"));
} else {
localFileHeader.setFileName(null);
throw new ZipException("Invalid entry name in local file header");
}

readExtraDataRecords(inputStream, localFileHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ public void testExtractZipFileWithNullAesExtraDataRecordThrowsException() throws
null, InternalZipConstants.BUFF_SIZE, false, 1);
}

@Test
public void testExtractZipFileWithFileNameLength0ThrowsException() throws IOException {
expectedException.expect(IOException.class);
expectedException.expectMessage("Invalid entry name in local file header");

extractZipFileWithInputStreams(TestUtils.getTestArchiveFromResources("file_name_size_is_0_in_local_file_header"),
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 e6c2d13

Please sign in to comment.