Skip to content

java.lang.IndexOutOfBoundsException in net.lingala.zip4j.io.inputstream.ZipEntryInputStream.readUntilBufferIsFull::ZipEntryInputStream.java:78 zip4j 2.9.0 #371

Closed
@ZanderHuang

Description

This vulnerability is of java.lang.IndexOutOfBoundsException, and can be triggered in latest version zip4j (2.9.0).
It is caused by getting an index of an array which is out of the range. and can be used for attackers to launch DoS (Denial of Service) attack for any java program that uses this library (since the user of zip4j doesn't know they need to catch this kind of exception) ( CWE-248: Uncaught exception).
Likely, the root cause of this crash is in net.lingala.zip4j.io.inputstream.ZipEntryInputStream.readUntilBufferIsFull::ZipEntryInputStream.java:78.

loopReadLength += inputStream.read(b, readLength, remainingLength);
Either variable "remainingLength" is index out of bounds for array "b" or both variables "remainingLength" and "readLength" are index out of bounds.

See more detail from the following crash stack.

Crash stack:

The crash thread's stack is as follows:

java.base/java.io.PushbackInputStream.read::PushbackInputStream.java:167
net.lingala.zip4j.io.inputstream.ZipEntryInputStream.readUntilBufferIsFull::ZipEntryInputStream.java:78
net.lingala.zip4j.io.inputstream.ZipEntryInputStream.readRawFully::ZipEntryInputStream.java:62
net.lingala.zip4j.io.inputstream.CipherInputStream.readRaw::CipherInputStream.java:71
net.lingala.zip4j.io.inputstream.AesCipherInputStream.getPasswordVerifier::AesCipherInputStream.java:168
net.lingala.zip4j.io.inputstream.AesCipherInputStream.initializeDecrypter::AesCipherInputStream.java:37
net.lingala.zip4j.io.inputstream.AesCipherInputStream.initializeDecrypter::AesCipherInputStream.java:18
net.lingala.zip4j.io.inputstream.CipherInputStream.<init>::CipherInputStream.java:25
net.lingala.zip4j.io.inputstream.AesCipherInputStream.<init>::AesCipherInputStream.java:32
net.lingala.zip4j.io.inputstream.ZipInputStream.initializeCipherInputStream::ZipInputStream.java:234
net.lingala.zip4j.io.inputstream.ZipInputStream.initializeEntryInputStream::ZipInputStream.java:223
net.lingala.zip4j.io.inputstream.ZipInputStream.getNextEntry::ZipInputStream.java:113
net.lingala.zip4j.io.inputstream.ZipInputStream.getNextEntry::ZipInputStream.java:83
com.test.Entry.main::Entry.java:37

Steps to reproduce:

  1. Build the following java code with the corresponding zip4j library (version 2.9.0).
## Download zip4j_env_reproduce.tar.gz from https://drive.google.com/file/d/1MekCBIghKxIW4j-TLjZkm8ovvLb_grm5/view?usp=sharing
tar -xf zip4j_env_reproduce.tar.gz
cd zip4j_env_reproduce
bash build.sh
  1. Run the built program to see the crash by feeding one of the poc file contained in the pocs.tar.gz, e.g. :
    (poc file can be downloaded from https://drive.google.com/file/d/1hviHw44Ym55ybVloEYYPwTtwlaIj0LvW/view?usp=sharing)
java -jar target/Entry-1.0-SNAPSHOT-jar-with-dependencies.jar pocs/crash-71415be583f0456949797dc42f9bcd265a067336

Any further discussion for this vulnerability including fix is welcomed!

Metadata

Labels

bugSomething isn't workingresolved

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions