Bug 46559 - org.apache.tools.zip.ZipFile leaves open file after RuntimeException
org.apache.tools.zip.ZipFile leaves open file after RuntimeException
Product: Ant
Classification: Unclassified
Component: Core
PC Windows XP
: P2 normal (vote)
: 1.8.0
Assigned To: Ant Notifications List
Depends on:
  Show dependency tree
Reported: 2009-01-19 04:59 UTC by Fred Stoki
Modified: 2009-01-29 05:25 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Fred Stoki 2009-01-19 04:59:28 UTC
When a corrupted zip is read the method "resolveLocalFileHeaderData()" will throw a RuntimeException. This exception is never caught so the archive file is never closed and remains opened.  The code calling constructor never gets a handle on the object, so you can't close the archive.  The Archive remains open until JVM exits.

    public ZipFile(File f, String encoding) throws IOException {
        this.encoding = encoding;
        archive = new RandomAccessFile(f, "r");
        try {
        } catch (IOException e) {
            try {
            } catch (IOException e2) {
                // swallow, throw the original exception instead
            throw e;

The RuntimeException stack
RuntimeException: data starting at 49679 is in unknown format
at org.apache.tools.zip.ZipEntry.setExtra(ZipEntry.java:268)
at org.apache.tools.zip.ZipFile.resolveLocalFileHeaderData(ZipFile.java:445)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:144)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:102)
Comment 1 Stefan Bodewig 2009-01-26 21:09:31 UTC
I can easily think of a patch, but would love to have a test case.

Can you provide a testcase that will trigger a RuntimeExcpetion inside the constructor?
Comment 2 Stefan Bodewig 2009-01-29 05:25:02 UTC
For now I've used the jar attached to bug 42940 which will need to be changed once that bug is fixed.

Testcase added and Ant fixed with svn revision 738853