Skip to content

java.lang.ArrayIndexOutOfBoundsException in net.lingala.zip4j.headers.HeaderReader.readAesExtraDataRecord::HeaderReader.java:675 zip4j 2.9.0 #366

Closed
@ZanderHuang

Description

@ZanderHuang

This vulnerability is of java.lang.ArrayIndexOutOfBoundsException, and can be triggered in latest version zip4j (2.9.0).
It is caused by missing check the array index < array size and also failing to catch the runtime java exception (it should be wrapped as one kind of JSONException) 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-129: Improper Validation of Array Index, CWE-248: Uncaught exception).
Likely, the root cause of this crash is in net.lingala.zip4j.headers.HeaderReader.readAesExtraDataRecord::HeaderReader.java:675.

System.arraycopy(aesData, 2, vendorIDBytes, 0, 2);
Lenght of variable "aesData" is less than 4 thus it results in ArrayIndexOutOfBoundsException.

See more detail from the following crash stack.

Crash stack:

The crash thread's stack is as follows:

java.base/java.lang.System.arraycopy::Native Method
net.lingala.zip4j.headers.HeaderReader.readAesExtraDataRecord::HeaderReader.java:675
net.lingala.zip4j.headers.HeaderReader.readAesExtraDataRecord::HeaderReader.java:642
net.lingala.zip4j.headers.HeaderReader.readLocalFileHeader::HeaderReader.java:576
net.lingala.zip4j.io.inputstream.ZipInputStream.getNextEntry::ZipInputStream.java:91
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/10H3WTdosQtnyq8St933R92WhIfAL7920/view?usp=sharing)
java -jar target/Entry-1.0-SNAPSHOT-jar-with-dependencies.jar pocs/crash-b10d5442f242277593267acb91a2f01fd0632413

Any further discussion for this vulnerability including fix is welcomed!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingresolved

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @srikanth-lingala@ZanderHuang

      Issue actions

        java.lang.ArrayIndexOutOfBoundsException in `net.lingala.zip4j.headers.HeaderReader.readAesExtraDataRecord::HeaderReader.java:675` zip4j 2.9.0 · Issue #366 · srikanth-lingala/zip4j