srikanth-lingala / zip4j

A Java library for zip files and streams
Apache License 2.0
2.09k stars 313 forks source link

Null Pointer Exception at getting inputstream #85

Closed jackielii closed 5 years ago

jackielii commented 5 years ago

with the following code

        val fn = "bigfile.zip"
        val zipFile = ZipFile(fn)
        val fh = zipFile.fileHeaders.firstOrNull()
        fh?.let {
            println(it.fileName)
            val input = zipFile.getInputStream(it)
        }

exception thrown at last line zipFile.getInputStream

I tracked it down through debugging, the exception is thrown at getCompressedSize:

java.lang.NullPointerException
    at net.lingala.zip4j.io.inputstream.ZipInputStream.getCompressedSize(ZipInputStream.java:290)
    at net.lingala.zip4j.io.inputstream.ZipInputStream.initializeEntryInputStream(ZipInputStream.java:199)
    at net.lingala.zip4j.io.inputstream.ZipInputStream.getNextEntry(ZipInputStream.java:106)
    at net.lingala.zip4j.util.UnzipUtil.createZipInputStream(UnzipUtil.java:29)
    at net.lingala.zip4j.ZipFile.getInputStream(ZipFile.java:782)

but It's actually because the compressionMethod is null : image

The root cause is because the compression code is 9 and it's not supported:

image

   4.4.5 compression method: (2 bytes)

        0 - The file is stored (no compression)
        1 - The file is Shrunk
        2 - The file is Reduced with compression factor 1
        3 - The file is Reduced with compression factor 2
        4 - The file is Reduced with compression factor 3
        5 - The file is Reduced with compression factor 4
        6 - The file is Imploded
        7 - Reserved for Tokenizing compression algorithm
        8 - The file is Deflated
        9 - Enhanced Deflating using Deflate64(tm)
       10 - PKWARE Data Compression Library Imploding (old IBM TERSE)
       11 - Reserved by PKWARE
       12 - File is compressed using BZIP2 algorithm
       13 - Reserved by PKWARE
       14 - LZMA
       15 - Reserved by PKWARE
       16 - IBM z/OS CMPSC Compression
       17 - Reserved by PKWARE
       18 - File is compressed using IBM TERSE (new)
       19 - IBM LZ77 z Architecture (PFS)
       96 - JPEG variant
       97 - WavPack compressed data
       98 - PPMd version I, Rev 1
       99 - AE-x encryption marker (see APPENDIX E)

So instead of returning null, it should really throw an exception here...

srikanth-lingala commented 5 years ago

Fixed in v2.2.3 released today