mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-19 10:07:12 +01:00
ensuring no input stream is left open
This commit is contained in:
@@ -237,6 +237,7 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
|
|
||||||
//make a copy
|
//make a copy
|
||||||
final Set<Dependency> dependencySet = findMoreDependencies(engine, tmpDir);
|
final Set<Dependency> dependencySet = findMoreDependencies(engine, tmpDir);
|
||||||
|
|
||||||
if (!dependencySet.isEmpty()) {
|
if (!dependencySet.isEmpty()) {
|
||||||
for (Dependency d : dependencySet) {
|
for (Dependency d : dependencySet) {
|
||||||
//fix the dependency's display name and path
|
//fix the dependency's display name and path
|
||||||
@@ -363,31 +364,43 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
}
|
}
|
||||||
archiveExt = archiveExt.toLowerCase();
|
archiveExt = archiveExt.toLowerCase();
|
||||||
|
|
||||||
FileInputStream fis;
|
final FileInputStream fis;
|
||||||
try {
|
try {
|
||||||
fis = new FileInputStream(archive);
|
fis = new FileInputStream(archive);
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
LOGGER.debug("", ex);
|
LOGGER.debug("", ex);
|
||||||
throw new AnalysisException("Archive file was not found.", ex);
|
throw new AnalysisException("Archive file was not found.", ex);
|
||||||
}
|
}
|
||||||
|
BufferedInputStream in = null;
|
||||||
|
ZipArchiveInputStream zin = null;
|
||||||
|
TarArchiveInputStream tin = null;
|
||||||
|
GzipCompressorInputStream gin = null;
|
||||||
|
BZip2CompressorInputStream bzin = null;
|
||||||
try {
|
try {
|
||||||
if (ZIPPABLES.contains(archiveExt)) {
|
if (ZIPPABLES.contains(archiveExt)) {
|
||||||
final BufferedInputStream in = new BufferedInputStream(fis);
|
in = new BufferedInputStream(fis);
|
||||||
ensureReadableJar(archiveExt, in);
|
ensureReadableJar(archiveExt, in);
|
||||||
extractArchive(new ZipArchiveInputStream(in), destination, engine);
|
zin = new ZipArchiveInputStream(in);
|
||||||
|
extractArchive(zin, destination, engine);
|
||||||
} else if ("tar".equals(archiveExt)) {
|
} else if ("tar".equals(archiveExt)) {
|
||||||
extractArchive(new TarArchiveInputStream(new BufferedInputStream(fis)), destination, engine);
|
in = new BufferedInputStream(fis);
|
||||||
|
tin = new TarArchiveInputStream(in);
|
||||||
|
extractArchive(tin, destination, engine);
|
||||||
} else if ("gz".equals(archiveExt) || "tgz".equals(archiveExt)) {
|
} else if ("gz".equals(archiveExt) || "tgz".equals(archiveExt)) {
|
||||||
final String uncompressedName = GzipUtils.getUncompressedFilename(archive.getName());
|
final String uncompressedName = GzipUtils.getUncompressedFilename(archive.getName());
|
||||||
final File f = new File(destination, uncompressedName);
|
final File f = new File(destination, uncompressedName);
|
||||||
if (engine.accept(f)) {
|
if (engine.accept(f)) {
|
||||||
decompressFile(new GzipCompressorInputStream(new BufferedInputStream(fis)), f);
|
in = new BufferedInputStream(fis);
|
||||||
|
gin = new GzipCompressorInputStream(in);
|
||||||
|
decompressFile(gin, f);
|
||||||
}
|
}
|
||||||
} else if ("bz2".equals(archiveExt) || "tbz2".equals(archiveExt)) {
|
} else if ("bz2".equals(archiveExt) || "tbz2".equals(archiveExt)) {
|
||||||
final String uncompressedName = BZip2Utils.getUncompressedFilename(archive.getName());
|
final String uncompressedName = BZip2Utils.getUncompressedFilename(archive.getName());
|
||||||
final File f = new File(destination, uncompressedName);
|
final File f = new File(destination, uncompressedName);
|
||||||
if (engine.accept(f)) {
|
if (engine.accept(f)) {
|
||||||
decompressFile(new BZip2CompressorInputStream(new BufferedInputStream(fis)), f);
|
in = new BufferedInputStream(fis);
|
||||||
|
bzin = new BZip2CompressorInputStream(in);
|
||||||
|
decompressFile(bzin, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ArchiveExtractionException ex) {
|
} catch (ArchiveExtractionException ex) {
|
||||||
@@ -397,7 +410,14 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
LOGGER.warn("Exception reading archive '{}'.", archive.getName());
|
LOGGER.warn("Exception reading archive '{}'.", archive.getName());
|
||||||
LOGGER.debug("", ex);
|
LOGGER.debug("", ex);
|
||||||
} finally {
|
} finally {
|
||||||
|
//overly verbose and not needed... but keeping it anyway due to
|
||||||
|
//having issue with file handles being left open
|
||||||
close(fis);
|
close(fis);
|
||||||
|
close(in);
|
||||||
|
close(zin);
|
||||||
|
close(tin);
|
||||||
|
close(gin);
|
||||||
|
close(bzin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user