|
@@ -585,15 +585,20 @@ public class FileUtil {
|
|
public static void unZip(File inFile, File unzipDir) throws IOException {
|
|
public static void unZip(File inFile, File unzipDir) throws IOException {
|
|
Enumeration<? extends ZipEntry> entries;
|
|
Enumeration<? extends ZipEntry> entries;
|
|
ZipFile zipFile = new ZipFile(inFile);
|
|
ZipFile zipFile = new ZipFile(inFile);
|
|
|
|
+ String targetDirPath = unzipDir.getCanonicalPath() + File.separator;
|
|
|
|
|
|
try {
|
|
try {
|
|
entries = zipFile.entries();
|
|
entries = zipFile.entries();
|
|
while (entries.hasMoreElements()) {
|
|
while (entries.hasMoreElements()) {
|
|
ZipEntry entry = entries.nextElement();
|
|
ZipEntry entry = entries.nextElement();
|
|
if (!entry.isDirectory()) {
|
|
if (!entry.isDirectory()) {
|
|
|
|
+ File file = new File(unzipDir, entry.getName());
|
|
|
|
+ if (!file.getCanonicalPath().startsWith(targetDirPath)) {
|
|
|
|
+ throw new IOException("expanding " + entry.getName()
|
|
|
|
+ + " would create file outside of " + unzipDir);
|
|
|
|
+ }
|
|
InputStream in = zipFile.getInputStream(entry);
|
|
InputStream in = zipFile.getInputStream(entry);
|
|
try {
|
|
try {
|
|
- File file = new File(unzipDir, entry.getName());
|
|
|
|
if (!file.getParentFile().mkdirs()) {
|
|
if (!file.getParentFile().mkdirs()) {
|
|
if (!file.getParentFile().isDirectory()) {
|
|
if (!file.getParentFile().isDirectory()) {
|
|
throw new IOException("Mkdirs failed to create " +
|
|
throw new IOException("Mkdirs failed to create " +
|
|
@@ -703,6 +708,13 @@ public class FileUtil {
|
|
|
|
|
|
private static void unpackEntries(TarArchiveInputStream tis,
|
|
private static void unpackEntries(TarArchiveInputStream tis,
|
|
TarArchiveEntry entry, File outputDir) throws IOException {
|
|
TarArchiveEntry entry, File outputDir) throws IOException {
|
|
|
|
+ String targetDirPath = outputDir.getCanonicalPath() + File.separator;
|
|
|
|
+ File outputFile = new File(outputDir, entry.getName());
|
|
|
|
+ if (!outputFile.getCanonicalPath().startsWith(targetDirPath)) {
|
|
|
|
+ throw new IOException("expanding " + entry.getName()
|
|
|
|
+ + " would create entry outside of " + outputDir);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (entry.isDirectory()) {
|
|
if (entry.isDirectory()) {
|
|
File subDir = new File(outputDir, entry.getName());
|
|
File subDir = new File(outputDir, entry.getName());
|
|
if (!subDir.mkdirs() && !subDir.isDirectory()) {
|
|
if (!subDir.mkdirs() && !subDir.isDirectory()) {
|
|
@@ -717,7 +729,6 @@ public class FileUtil {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- File outputFile = new File(outputDir, entry.getName());
|
|
|
|
if (!outputFile.getParentFile().exists()) {
|
|
if (!outputFile.getParentFile().exists()) {
|
|
if (!outputFile.getParentFile().mkdirs()) {
|
|
if (!outputFile.getParentFile().mkdirs()) {
|
|
throw new IOException("Mkdirs failed to create tar internal dir "
|
|
throw new IOException("Mkdirs failed to create tar internal dir "
|