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

zip4j 2.0.3: when execute ZipFile.getInputStream(FileHeader), java.lang.ArrayIndexOutOfBoundsException happened. #14

Closed
dancencheung opened this issue Jul 9, 2019 · 2 comments
Assignees

Comments

@dancencheung
Copy link

dancencheung commented Jul 9, 2019

Code:

public static void main(String[] args)
{
	try
	{
		String zipFilePath = "D:\\temp\\GoogleInstaller_3.0.zip";
		String filePathInZip = "classes.dex";
		ZipFile zipFile = new ZipFile(zipFilePath);				
		FileHeader fileHeader = zipFile.getFileHeader(filePathInZip);
		
		if(null != fileHeader && !fileHeader.isDirectory())
		{
			zipFile.getInputStream(fileHeader);
		}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
}

Exception:
java.lang.ArrayIndexOutOfBoundsException: 3
at net.lingala.zip4j.util.RawIO.readShortLittleEndian(RawIO.java:107)
at net.lingala.zip4j.headers.HeaderReader.parseExtraDataRecords(HeaderReader.java:303)
at net.lingala.zip4j.headers.HeaderReader.readExtraDataRecords(HeaderReader.java:279)
at net.lingala.zip4j.headers.HeaderReader.readExtraDataRecords(HeaderReader.java:256)
at net.lingala.zip4j.headers.HeaderReader.readCentralDirectory(HeaderReader.java:208)
at net.lingala.zip4j.headers.HeaderReader.readAllHeaders(HeaderReader.java:75)
at net.lingala.zip4j.ZipFile.readZipInfo(ZipFile.java:831)
at net.lingala.zip4j.ZipFile.getFileHeader(ZipFile.java:565)
at com.dancen.util.filecompressor.MyZipUtil.main(MyZipUtil.java:37)

Usually, I can execute ZipFile.getInputStream(FileHeader) successfull, but for the file "GoogleInstaller_3.0.zip", ArrayIndexOutOfBoundsException throwed. I have attached the file.

GoogleInstaller_3.0.zip

@srikanth-lingala srikanth-lingala self-assigned this Jul 9, 2019
@srikanth-lingala
Copy link
Owner

Technically speaking, this is a corrupt zip file. Without going into too many details, the issue with this zip file is that some header information is not as long as the length that should be for these headers. A block of zip headers tells how long certain headers (extra data records) are in the zip headers. This length is defined as 3 in this zip file, but this length has to be at least 4, and even 4 is wrong, but at least acceptable. Ideally it should be more than 4. But a length of 3 is definitely wrong.

However, this part of headers contain some additional information of the file, and the zip file can still be extracted even if these headers are corrupt. I will include a fix to skip these headers if these headers are corrupt. I will let you know when the fix is ready.

@srikanth-lingala
Copy link
Owner

Fixed in v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants