You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2021/12/13 09:16:25 UTC

[Bug 65744] New: java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

            Bug ID: 65744
           Summary: java.lang.NullPointerException in
                    `org.apache.poi.openxml4j.util.ZipArchiveThresholdInpu
                    tStream.checkThreshold::ZipArchiveThresholdInputStream
                    .java:113` poi 5.1.0
           Product: POI
           Version: 5.0.x-dev
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: OPC
          Assignee: dev@poi.apache.org
          Reporter: wenjiezander@gmail.com
  Target Milestone: ---

# java.lang.NullPointerException in
`org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113`
poi 5.1.0

This vulnerability is of java.lang.NullPointerException, and can be triggered
in latest version poi (5.1.0).
It is caused by not checking the pointer before dereference it and also failing
to catch the runtime java exception (it should be wrapped as one kind of
JSONException), and can .
Likely, the root cause of this crash is in
`org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113`.
See more detail from the following crash stack.

# Crash stack:
The crash thread's stack is as follows:

```
org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.getCompressedCount::ZipArchiveInputStream.java:559
org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113
org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.read::ZipArchiveThresholdInputStream.java:82
org.apache.poi.util.IOUtils.toByteArray::IOUtils.java:185
org.apache.poi.util.IOUtils.toByteArray::IOUtils.java:153
org.apache.poi.openxml4j.util.ZipArchiveFakeEntry.<init>::ZipArchiveFakeEntry.java:67
org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.<init>::ZipInputStreamZipEntrySource.java:98
org.apache.poi.openxml4j.opc.ZipPackage.<init>::ZipPackage.java:132
org.apache.poi.openxml4j.opc.OPCPackage.open::OPCPackage.java:312
org.apache.poi.ooxml.util.PackageHelper.open::PackageHelper.java:47
org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>::XSSFWorkbook.java:296
com.test.Entry.main::Entry.java:32
```


# Steps to reproduce:

1. Build the following java code with the corresponding poi library (version
5.1.0).

```
## Download poi_env_reproduce.zip from
https://drive.google.com/file/d/1N4gUC0MF-SAN-Xz0van0_7TbNj4aUuFd/view?usp=sharing
unzip poi_env_reproduce.zip
cd poi_env_reproduce
bash build.sh
```

2. Run the built program to see the crash by feeding one of the poc file
contained in the pocs.tar.gz, e.g. :

```bash
java -jar target/Entry-1.0-SNAPSHOT-jar-with-dependencies.jar
pocs/crash-bfc98720de6906ac401f1c2bbf5257a6bc3696a8
```

Any further discussion for this vulnerability including fix is welcomed!
Feel free to contact me at wenjiezander@gmail.com
(https://github.com/ZanderHuang)

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65744] java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

PJ Fanning <fa...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65744] java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

--- Comment #2 from PJ Fanning <fa...@yahoo.com> ---
this is not how we accept issues - please attach the microsoft format file that
is causing the issue to the bugzilla issue

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65744] java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

--- Comment #6 from PJ Fanning <fa...@yahoo.com> ---
marking all these as need info - can you explain in plain English what you are
testing? are you testing that POI can't handle garbage input? and what do you
expect POI to do when it gets garbage input?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65744] java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

--- Comment #8 from wenjiezander@gmail.com ---
I have tested in 5.2.0-SNAPSHOT taken from
https://ci-builds.apache.org/job/POI/job/POI-DSL-1.8/lastSuccessfulBuild/artifact/build/dist/

This bug is fixed and the exception is caught by newly implemented
POIXMLException.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65744] java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

--- Comment #5 from PJ Fanning <fa...@yahoo.com> ---
the latest (unreleased) code handles the NPE already.

```
        long rawSize;
        try {
            rawSize = stats.getCompressedCount();
        } catch (NullPointerException e) {
            // this can happen with a very specially crafted file
            // see https://issues.apache.org/jira/browse/COMPRESS-598 for a
related bug-report
            // therefore we try to handle this gracefully for now
            // this try/catch can be removed when COMPRESS-598 is fixed
            rawSize = 0;
        }
```

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65744] java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

--- Comment #7 from wenjiezander@gmail.com ---
(In reply to PJ Fanning from comment #6)
> marking all these as need info - can you explain in plain English what you
> are testing? are you testing that POI can't handle garbage input? and what
> do you expect POI to do when it gets garbage input?

I am testing the robustness of POI using fuzzing with massive auto-generated
inputs.

Developers who are integrating POI into their program, may not be aware of the
uncaught exceptions. As a result, the stability of the program is compromised.

If this POI API only expects certain file format, it is better to implement
some validation checks instead of accepting all file types to avoid the
uncaught exceptions.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65744] java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

--- Comment #3 from wenjiezander@gmail.com ---
Created attachment 38128
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=38128&action=edit
The poc file causes java.lang.NullPointerException in
org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold--ZipArchiveThresholdInputStream.java-113

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65744] java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

--- Comment #4 from PJ Fanning <fa...@yahoo.com> ---
what is that 807 byte attachment? - nothing on my machine recognises that as a
valid file

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65744] java.lang.NullPointerException in `org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold::ZipArchiveThresholdInputStream.java:113` poi 5.1.0

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65744

wenjiezander@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from wenjiezander@gmail.com ---
The poc file and report can be downloaded from
https://drive.google.com/drive/folders/1RsDEtpjmv3adeLg0E0H4g4FicUKxdpgG?usp=sharing

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org