Skip to content

Commit a86e460

Browse files
committed
resolving merge conflicts with PR #1331
2 parents 3e5ebdb + 38af23d commit a86e460

File tree

13 files changed

+407
-232
lines changed

13 files changed

+407
-232
lines changed

core/src/main/java/oracle/weblogic/deploy/util/FileUtils.java

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.util;
@@ -8,7 +8,6 @@
88
import java.io.File;
99
import java.io.FileInputStream;
1010
import java.io.FileNotFoundException;
11-
import java.io.FileOutputStream;
1211
import java.io.FilenameFilter;
1312
import java.io.IOException;
1413
import java.io.InputStream;
@@ -24,8 +23,6 @@
2423
import java.util.List;
2524
import java.util.Locale;
2625
import java.util.Set;
27-
import java.util.zip.ZipEntry;
28-
import java.util.zip.ZipInputStream;
2926
import javax.xml.bind.DatatypeConverter;
3027

3128
import oracle.weblogic.deploy.exception.ExceptionHelper;
@@ -617,75 +614,10 @@ public static byte[] readInputStreamToByteArray(InputStream input) throws IOExce
617614
return outputStream.toByteArray();
618615
}
619616

620-
public static File writeInputStreamToFile(InputStream input, String fileName) throws IOException {
621-
File tmpdir = getTmpDir();
622-
File file = new File(tmpdir, fileName);
623-
try (FileOutputStream fos = new FileOutputStream(file)) {
624-
byte[] byteArray = FileUtils.readInputStreamToByteArray(input);
625-
fos.write(byteArray);
626-
}
627-
return file;
628-
}
629-
630617
public static File getTmpDir() {
631618
return new File(System.getProperty("java.io.tmpdir"));
632619
}
633620

634-
public static void extractZipFileContent(WLSDeployArchive archiveFile, String zipEntry, String extractPath) {
635-
final String METHOD = "extractZipFileContent";
636-
637-
try {
638-
if (zipEntry != null) {
639-
File extractDir = new File(extractPath);
640-
extractDir.mkdirs();
641-
String walletZip = archiveFile.extractFile(zipEntry,
642-
Files.createTempDirectory("tempwallet").toFile());
643-
644-
if (!Files.exists(Paths.get(extractPath))) {
645-
Files.createDirectory(Paths.get(extractPath));
646-
}
647-
648-
// verify that each target file is under the extract directory,
649-
// to protect from the file overwrite security vulnerability (zip slip).
650-
String canonicalExtractPath = extractDir.getCanonicalPath();
651-
652-
byte[] buffer = new byte[1024];
653-
FileInputStream fis = new FileInputStream(walletZip);
654-
ZipInputStream zis = new ZipInputStream(fis);
655-
ZipEntry ze = zis.getNextEntry();
656-
while (ze != null) {
657-
String fileName = ze.getName();
658-
File newFile = new File(extractPath + File.separator + fileName);
659-
String canonicalNewFile = newFile.getCanonicalPath();
660-
if(!canonicalNewFile.startsWith(canonicalExtractPath + File.separator)) {
661-
throw new WLSDeployArchiveIOException("WLSDPLY-01119", ze.getName());
662-
}
663-
664-
new File(newFile.getParent()).mkdirs();
665-
FileOutputStream fos = new FileOutputStream(newFile);
666-
int len = zis.read(buffer);
667-
while (len > 0) {
668-
fos.write(buffer, 0, len);
669-
len = zis.read(buffer);
670-
}
671-
fos.close();
672-
zis.closeEntry();
673-
ze = zis.getNextEntry();
674-
}
675-
zis.closeEntry();
676-
zis.close();
677-
fis.close();
678-
Files.delete(Paths.get(walletZip));
679-
}
680-
} catch (IOException | WLSDeployArchiveIOException ioe) {
681-
String message = ExceptionHelper.getMessage("WLSDPLY-01118", archiveFile.getArchiveFileName(),
682-
ioe.getLocalizedMessage());
683-
IllegalArgumentException iae = new IllegalArgumentException(message);
684-
LOGGER.throwing(CLASS, METHOD, iae);
685-
throw iae;
686-
}
687-
}
688-
689621
/**
690622
* Return a PrintWriter instance for the provided file name.
691623
* @param fileName Name of output file

0 commit comments

Comments
 (0)