bodewig 2005/05/13 01:09:22
Modified: . WHATSNEW
src/main/org/apache/tools/ant/taskdefs Untar.java
src/main/org/apache/tools/zip ZipFile.java
Log:
<unzip> and <untar> could leave streams open. PR 34893
Revision Changes Path
1.820 +3 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.819
retrieving revision 1.820
diff -u -r1.819 -r1.820
--- WHATSNEW 11 May 2005 19:37:13 -0000 1.819
+++ WHATSNEW 13 May 2005 08:09:22 -0000 1.820
@@ -213,6 +213,9 @@
* Granularity attribute for <sync> task was undocumented.
Bugzilla report 34871.
+* <unzip> and <untar> could leave file handles open on invalid
+ archives. Bugzilla report 34893.
+
Other changes:
--------------
1.46 +7 -3 ant/src/main/org/apache/tools/ant/taskdefs/Untar.java
Index: Untar.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Untar.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- Untar.java 6 Jan 2005 17:50:29 -0000 1.45
+++ Untar.java 13 May 2005 08:09:22 -0000 1.46
@@ -90,13 +90,13 @@
* @see Expand#expandFile(FileUtils, File, File)
*/
protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
+ FileInputStream fis = null;
TarInputStream tis = null;
try {
log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
+ fis = new FileInputStream(srcF);
tis = new TarInputStream(
- compression.decompress(srcF,
- new BufferedInputStream(
- new FileInputStream(srcF))));
+ compression.decompress(srcF, new BufferedInputStream(fis)));
TarEntry te = null;
FileNameMapper mapper = getMapper();
while ((te = tis.getNextEntry()) != null) {
@@ -111,6 +111,10 @@
ioe, getLocation());
} finally {
FileUtils.close(tis);
+ if (tis == null) {
+ FileUtils.close(fis);
+ }
+
}
}
1.19 +11 -2 ant/src/main/org/apache/tools/zip/ZipFile.java
Index: ZipFile.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ZipFile.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ZipFile.java 9 Mar 2005 00:20:39 -0000 1.18
+++ ZipFile.java 13 May 2005 08:09:22 -0000 1.19
@@ -138,8 +138,17 @@
public ZipFile(File f, String encoding) throws IOException {
this.encoding = encoding;
archive = new RandomAccessFile(f, "r");
- populateFromCentralDirectory();
- resolveLocalFileHeaderData();
+ try {
+ populateFromCentralDirectory();
+ resolveLocalFileHeaderData();
+ } catch (IOException e) {
+ try {
+ archive.close();
+ } catch (IOException e2) {
+ // swallow, throw the original exception instead
+ }
+ throw e;
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]