Browse Source

<unzip> and <untar> could leave streams open. PR 34893

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278254 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 20 years ago
parent
commit
b977b55da6
3 changed files with 21 additions and 5 deletions
  1. +3
    -0
      WHATSNEW
  2. +7
    -3
      src/main/org/apache/tools/ant/taskdefs/Untar.java
  3. +11
    -2
      src/main/org/apache/tools/zip/ZipFile.java

+ 3
- 0
WHATSNEW View File

@@ -213,6 +213,9 @@ Fixed bugs:
* Granularity attribute for <sync> task was undocumented. * Granularity attribute for <sync> task was undocumented.
Bugzilla report 34871. Bugzilla report 34871.


* <unzip> and <untar> could leave file handles open on invalid
archives. Bugzilla report 34893.

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




+ 7
- 3
src/main/org/apache/tools/ant/taskdefs/Untar.java View File

@@ -90,13 +90,13 @@ public class Untar extends Expand {
* @see Expand#expandFile(FileUtils, File, File) * @see Expand#expandFile(FileUtils, File, File)
*/ */
protected void expandFile(FileUtils fileUtils, File srcF, File dir) { protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
FileInputStream fis = null;
TarInputStream tis = null; TarInputStream tis = null;
try { try {
log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO); log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
fis = new FileInputStream(srcF);
tis = new TarInputStream( tis = new TarInputStream(
compression.decompress(srcF,
new BufferedInputStream(
new FileInputStream(srcF))));
compression.decompress(srcF, new BufferedInputStream(fis)));
TarEntry te = null; TarEntry te = null;
FileNameMapper mapper = getMapper(); FileNameMapper mapper = getMapper();
while ((te = tis.getNextEntry()) != null) { while ((te = tis.getNextEntry()) != null) {
@@ -111,6 +111,10 @@ public class Untar extends Expand {
ioe, getLocation()); ioe, getLocation());
} finally { } finally {
FileUtils.close(tis); FileUtils.close(tis);
if (tis == null) {
FileUtils.close(fis);
}
} }
} }




+ 11
- 2
src/main/org/apache/tools/zip/ZipFile.java View File

@@ -138,8 +138,17 @@ 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");
populateFromCentralDirectory();
resolveLocalFileHeaderData();
try {
populateFromCentralDirectory();
resolveLocalFileHeaderData();
} catch (IOException e) {
try {
archive.close();
} catch (IOException e2) {
// swallow, throw the original exception instead
}
throw e;
}
} }


/** /**


Loading…
Cancel
Save