git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@738853 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -331,6 +331,11 @@ Fixed bugs: | |||||
| * <sort> resource collection kept only one of entries deemed equal by | * <sort> resource collection kept only one of entries deemed equal by | ||||
| the chosen Comparator. Bugzilla report 46527. | 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: | Other changes: | ||||
| -------------- | -------------- | ||||
| @@ -150,16 +150,19 @@ public class ZipFile { | |||||
| public ZipFile(File f, String encoding) throws IOException { | public ZipFile(File f, String encoding) throws IOException { | ||||
| this.encoding = encoding; | this.encoding = encoding; | ||||
| archive = new RandomAccessFile(f, "r"); | archive = new RandomAccessFile(f, "r"); | ||||
| boolean success = false; | |||||
| try { | try { | ||||
| populateFromCentralDirectory(); | populateFromCentralDirectory(); | ||||
| resolveLocalFileHeaderData(); | 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; | |||||
| } | } | ||||
| } | } | ||||
| @@ -43,4 +43,18 @@ | |||||
| dest="${output}"/> | dest="${output}"/> | ||||
| <au:assertFileExists file="${output}/foo/file"/> | <au:assertFileExists file="${output}/foo/file"/> | ||||
| </target> | </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> | </project> | ||||