Browse Source

Make sure ZIP archive is closed even when a RuntimeExpection occurs. PR 46559

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@738853 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
601cdf67ba
5 changed files with 28 additions and 6 deletions
  1. +5
    -0
      WHATSNEW
  2. +9
    -6
      src/main/org/apache/tools/zip/ZipFile.java
  3. +14
    -0
      src/tests/antunit/taskdefs/unzip-test.xml
  4. BIN
      src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip
  5. BIN
      src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip

+ 5
- 0
WHATSNEW View File

@@ -331,6 +331,11 @@ Fixed bugs:
* <sort> resource collection kept only one of entries deemed equal by
the chosen Comparator. Bugzilla report 46527.

* the ZipFile class used by <unzip> and others could leave the
archive open (making it undeletable on Windows as long as the java
VM was running) for files with an unexpected internal structure.
Bugzilla Report 46559.

Other changes:
--------------



+ 9
- 6
src/main/org/apache/tools/zip/ZipFile.java View File

@@ -150,16 +150,19 @@ public class ZipFile {
public ZipFile(File f, String encoding) throws IOException {
this.encoding = encoding;
archive = new RandomAccessFile(f, "r");
boolean success = false;
try {
populateFromCentralDirectory();
resolveLocalFileHeaderData();
} catch (IOException e) {
try {
archive.close();
} catch (IOException e2) {
// swallow, throw the original exception instead
success = true;
} finally {
if (!success) {
try {
archive.close();
} catch (IOException e2) {
// swallow, throw the original exception instead
}
}
throw e;
}
}



+ 14
- 0
src/tests/antunit/taskdefs/unzip-test.xml View File

@@ -43,4 +43,18 @@
dest="${output}"/>
<au:assertFileExists file="${output}/foo/file"/>
</target>

<target name="testArchiveIsClosedForInvalidZips"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=46559"
>
<mkdir dir="${input}"/>
<mkdir dir="${output}"/>
<copy file="zip/Bugzilla-46559.zip" tofile="${input}/test.zip"/>
<au:expectfailure>
<unzip src="${input}/test.zip" dest="${output}"/>
</au:expectfailure>
<delete file="${input}/test.zip" quiet="true"/>
<!-- failed on Windows and other OSes with implicit file locking -->
<au:assertFileDoesntExist file="${input}/test.zip"/>
</target>
</project>

BIN
src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip View File


BIN
src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip View File


Loading…
Cancel
Save