Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutofBoundsException when read directory from zipInputStream #33

Closed
IvanLi123 opened this issue Jul 31, 2019 · 7 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@IvanLi123
Copy link

Hi, Author. I found out this bug that when I tried to read encrypted zip files from ZipInputStream, if it meet some directories, it would throw this exception:
java.lang.ArrayIndexOutOfBoundsException: 11
at net.lingala.zip4j.util.RawIO.readShortLittleEndian(RawIO.java:109)
at net.lingala.zip4j.headers.HeaderReader.parseExtraDataRecords(HeaderReader.java:309)
at net.lingala.zip4j.headers.HeaderReader.readExtraDataRecords(HeaderReader.java:297)
at net.lingala.zip4j.headers.HeaderReader.readExtraDataRecords(HeaderReader.java:264)
at net.lingala.zip4j.headers.HeaderReader.readLocalFileHeader(HeaderReader.java:553)
at net.lingala.zip4j.io.inputstream.ZipInputStream.getNextEntry(ZipInputStream.java:66)
at net.lingala.zip4j.io.inputstream.ZipInputStream.getNextEntry(ZipInputStream.java:62)

This error only happens on reading directories from ZipInputStream.
Please help me fix this bug. I am in urgent need.

Thank you in advance!

@IvanLi123
Copy link
Author

directory.zip
Zip file attached.

@srikanth-lingala
Copy link
Owner

Can you please give me the password for the zip file and also the code you used? I have not been able to reproduce this issue with some sample zip files which have directories in it. For me ZipInputStream works fine.

@IvanLi123
Copy link
Author

IvanLi123 commented Aug 1, 2019

Can you please give me the password for the zip file and also the code you used? I have not been able to reproduce this issue with some sample zip files which have directories in it. For me ZipInputStream works fine.

The password is password.
The code I used is:

   File file = new File("/home/yifan.li/Documents/directory.zip");
        FileInputStream fileInputStream = new FileInputStream(file);
        ZipInputStream zipInputStream = new ZipInputStream(fileInputStream, "password".toCharArray());
        LocalFileHeader localFileHeader;
        int readLen = 0;
        byte[] buffer = new byte[1024];
        while ((localFileHeader = zipInputStream.getNextEntry()) != null) {
            while ((readLen = zipInputStream.read(buffer)) != -1) {

            }
        }

Did I use it in a wrong way? I also tried copying your code on the readme.md, didn't work either.
Another issue I found is when I tried to read the password protected zip files on hdfs, I need to wrap the FSDataInputStream with BufferedInputStream or BytesInputStream. Otherwise it won't read anything. I know this API is only for the local files. Perhaps the problem is on the hdfs side.
Anyway, thank you for you reply and help.

@IvanLi123
Copy link
Author

Hi, Srikanth, I am using Ubuntu. Before I just right clicked on the folder and clicked "compress" using this GUI to compress the folder. But when I tried to create the zip file from command line like "zip -re filename.zip folderpath password", it wouldn't throw this ArrayIndexOutofBoundsException.

That's weird.

@srikanth-lingala
Copy link
Owner

Apparently, Ubuntu is creating some corrupt extra data headers for some of the entries in the zip file. These headers are some additional information and the zip file can still be extracted without them. I have pushed a fix to ignore such headers. I will include this fix in the next release

@IvanLi123
Copy link
Author

Apparently, Ubuntu is creating some corrupt extra data headers for some of the entries in the zip file. These headers are some additional information and the zip file can still be extracted without them. I have pushed a fix to ignore such headers. I will include this fix in the next release

Thank you!

@srikanth-lingala srikanth-lingala self-assigned this Aug 9, 2019
@srikanth-lingala srikanth-lingala added the bug Something isn't working label Aug 9, 2019
@srikanth-lingala
Copy link
Owner

Fixed in v2.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants