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 2016/09/13 19:42:35 UTC
[Bug 60128] New: File left open in ZipPackage when
InvalidFormatException are raised
https://bz.apache.org/bugzilla/show_bug.cgi?id=60128
Bug ID: 60128
Summary: File left open in ZipPackage when
InvalidFormatException are raised
Product: POI
Version: 3.15-dev
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P2
Component: OPC
Assignee: dev@poi.apache.org
Reporter: matafagafo@yahoo.com
Created attachment 34243
--> https://bz.apache.org/bugzilla/attachment.cgi?id=34243&action=edit
A invalid format file
ZipPackage isn't closing opened files when InvalidFormatExceptions are raised.
Running the code bellow, using the provided sample file, shows the problem,
while the sample code is running the file is open in operation system (you have
to use some SO tool to verify this).
Some details:
* To run you have to correct the path to provided file.
* The provided file is a invalid XLSX file, was created just to generate the
problem.
The Exception trace
at
org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:238)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:726)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:228)
at Main.main(Main.java:14)
It's happen because ZipPackage opens the file but don't close it when a
Exception is raised.
The sample code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
public class Main {
public static void main(String[] args) throws IOException {
OPCPackage pkg = null;
try {
pkg = OPCPackage.open("C:/Temp/invalid file.xlsx",
PackageAccess.READ);
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (pkg != null) {
pkg.close();
}
}
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
String s;
while ((s = in.readLine()) != null && s.length() != 0) {
// Enter to end sample
}
}
}
--
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 60128] File left open in ZipPackage when InvalidFormatException
are raised
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60128
Matafagafo <ma...@yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEEDINFO |NEW
--- Comment #4 from Matafagafo <ma...@yahoo.com> ---
(In reply to Javen O'Neal from comment #3)
> Based on the line numbers in comment 0, it looks like Matafagafo is using
> POI 3.15 beta 2 or a trunk release between r1749795 (2016-06-22) and
> r1752997 (2016-07-16)
You are right, the stack is from POI 3.15 beta 2.
Sorry for the lack of info.
--
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 60128] File left open in ZipPackage when InvalidFormatException
are raised
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60128
Javen O'Neal <on...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #5 from Javen O'Neal <on...@apache.org> ---
Changes from Throwable#addSuppress to Throwable#printStackTrace() to maintain
Java 6 compatibility in r1760732.
Updated changelog in r1760734
Please reopen if the problem persists with the latest trunk build or the
exception handling can be improved on.
--
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 60128] File left open in ZipPackage when InvalidFormatException
are raised
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60128
--- Comment #6 from Javen O'Neal <on...@apache.org> ---
r1760735 add test-data/openxml4j/invalid.xlsx to expected failures for
integration test
--
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 60128] File left open in ZipPackage when InvalidFormatException
are raised
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60128
Nick Burch <ap...@gagravarr.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |NEEDINFO
--- Comment #1 from Nick Burch <ap...@gagravarr.org> ---
Are you sure this is still happening on trunk?
OPCPackage has a bunch of catches in the open block, which attempt to close the
faulty package before triggering the exception. I've added some unit tests in
r1760693 which verify that the call to close on a faulty package does actually
close the underlying stream/file. As such, I can't see how things aren't
getting closed?
--
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 60128] File left open in ZipPackage when InvalidFormatException
are raised
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60128
Javen O'Neal <on...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS|Windows NT |All
Severity|normal |critical
--
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 60128] File left open in ZipPackage when InvalidFormatException
are raised
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60128
--- Comment #3 from Javen O'Neal <on...@apache.org> ---
Based on the line numbers in comment 0, it looks like Matafagafo is using POI
3.15 beta 2 or a trunk release between r1749795 (2016-06-22) and r1752997
(2016-07-16)
--
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 60128] File left open in ZipPackage when InvalidFormatException
are raised
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60128
--- Comment #2 from Javen O'Neal <on...@apache.org> ---
I found a couple spots where opened files were not closed when raising
exceptions. The one mentioned in comment 0, caused by OPCPackage.open not
closing the ZipPackage when pack.getParts() failed is fixed [1].
I found some other cases in the ZipPackage constructors that could fail without
cleaning up their resources. [2]
I committed these changes in r1760702. They will likely be included in the POI
3.15 final release.
This commit is in desperate need of cleanup for someone who knows what they're
doing with Java exception handling. This is admittedly beyond my skills.
Thanks for the test file, code, and stack trace. Got any ideas how we can check
for unclosed resources in our unit tests? In TestZipPackage, we're using
assertTrue(tmpFile.delete()) [3]
[1] OPCPackage.java
https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java?r1=1760702&r2=1760701&pathrev=1760702
[2] ZipPackage.java
https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?r1=1760702&r2=1760701&pathrev=1760702
[3] TestZipPackage.java
https://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java?r1=1760702&r2=1760701&pathrev=1760702
--
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 60128] File left open in ZipPackage when InvalidFormatException
are raised
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60128
--- Comment #7 from Javen O'Neal <on...@apache.org> ---
r1760743 add test-data/openxml4j/invalid.xlsx to additional expected failures
for integration test
--
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