File tree 2 files changed +20
-0
lines changed
main/java/net/lingala/zip4j/headers
test/java/net/lingala/zip4j
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,10 @@ public class HeaderReader {
66
66
67
67
public ZipModel readAllHeaders (RandomAccessFile zip4jRaf , Zip4jConfig zip4jConfig ) throws IOException {
68
68
69
+ if (zip4jRaf .length () == 0 ) {
70
+ return new ZipModel ();
71
+ }
72
+
69
73
if (zip4jRaf .length () < ENDHDR ) {
70
74
throw new ZipException ("Zip file size less than minimum expected zip file size. " +
71
75
"Probably not a zip file or a corrupted zip file" );
Original file line number Diff line number Diff line change @@ -949,6 +949,22 @@ public void testAddStreamWithStoreCompressionAndAesEncryptionWorksFine() throws
949
949
extractZipFileWithStream (generatedZipFile , PASSWORD );
950
950
}
951
951
952
+ @ Test
953
+ public void testAddStreamToAnEmptyFileDoesNotThrowException () throws IOException {
954
+ if (!generatedZipFile .createNewFile ()) {
955
+ throw new RuntimeException ("Cannot create an empty file to test" );
956
+ }
957
+ File fileToAdd = TestUtils .getTestFileFromResources ("sample.pdf" );
958
+ try (ZipFile zipFile = new ZipFile (generatedZipFile );
959
+ InputStream inputStream = Files .newInputStream (fileToAdd .toPath ())) {
960
+ ZipParameters zipParameters = new ZipParameters ();
961
+ zipParameters .setFileNameInZip (fileToAdd .getName ());
962
+ zipFile .addStream (inputStream , zipParameters );
963
+ }
964
+
965
+ ZipFileVerifier .verifyZipFileByExtractingAllFiles (generatedZipFile , outputFolder , 1 );
966
+ }
967
+
952
968
@ Test
953
969
public void testAddFolderWithCustomBufferSize () throws IOException {
954
970
ZipFile zipFile = new ZipFile (generatedZipFile );
You can’t perform that action at this time.
0 commit comments