|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. |
| 2 | + * Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. |
3 | 3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
|
4 | 4 | */
|
5 | 5 | package oracle.weblogic.deploy.util;
|
|
8 | 8 | import java.io.File;
|
9 | 9 | import java.io.FileInputStream;
|
10 | 10 | import java.io.FileNotFoundException;
|
11 |
| -import java.io.FileOutputStream; |
12 | 11 | import java.io.FilenameFilter;
|
13 | 12 | import java.io.IOException;
|
14 | 13 | import java.io.InputStream;
|
|
24 | 23 | import java.util.List;
|
25 | 24 | import java.util.Locale;
|
26 | 25 | import java.util.Set;
|
27 |
| -import java.util.zip.ZipEntry; |
28 |
| -import java.util.zip.ZipInputStream; |
29 | 26 | import javax.xml.bind.DatatypeConverter;
|
30 | 27 |
|
31 | 28 | import oracle.weblogic.deploy.exception.ExceptionHelper;
|
@@ -617,75 +614,10 @@ public static byte[] readInputStreamToByteArray(InputStream input) throws IOExce
|
617 | 614 | return outputStream.toByteArray();
|
618 | 615 | }
|
619 | 616 |
|
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 |
| - |
630 | 617 | public static File getTmpDir() {
|
631 | 618 | return new File(System.getProperty("java.io.tmpdir"));
|
632 | 619 | }
|
633 | 620 |
|
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 |
| - |
689 | 621 | /**
|
690 | 622 | * Return a PrintWriter instance for the provided file name.
|
691 | 623 | * @param fileName Name of output file
|
|
0 commit comments