From 37a3f3dd7b72fa99a6b8d2dde2bd2872f1858649 Mon Sep 17 00:00:00 2001 From: "prakash.e@huawei.com" Date: Tue, 5 Apr 2022 15:09:02 +0530 Subject: Added new parameter to store file path. https://sonarcloud.io/project/issues?resolved=false&severities=BLOCKER&id=onap_vnfsdk-validation&open=AXem3AYTgLw0BJ6Agbf8 https://sonarcloud.io/project/issues?resolved=false&severities=BLOCKER&id=onap_vnfsdk-validation&open=AXem3AYTgLw0BJ6Agbf9 https://sonarcloud.io/project/issues?resolved=false&severities=BLOCKER&id=onap_vnfsdk-validation&open=AXem3AYTgLw0BJ6Agbf7 Issue-ID: VNFSDK-832 Signed-off-by: prakash.e@huawei.com Change-Id: I7ae4a6256c870aa4921f31e5959939a23c075e3e --- .../src/main/java/org/onap/cvc/csar/FileArchive.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/FileArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/FileArchive.java index 1d6b62f..8446f4c 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/FileArchive.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/FileArchive.java @@ -31,7 +31,6 @@ import java.util.Optional; import java.util.stream.Stream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import static org.onap.cvc.csar.CSARArchive.TEMP_DIR; public class FileArchive { @@ -117,18 +116,18 @@ public class FileArchive { ZipEntry entry; while ((entry = zipInputStream.getNextEntry()) != null) { String pathname = destination + File.separator + entry.getName(); - if (!pathname.startsWith(TEMP_DIR)) { + if (!pathname.startsWith(String.valueOf(destination))) { throw new IOException("Entry is outside of the target directory"); } File filePath = new File(pathname); if(entry.isDirectory()){ - filePath.mkdirs(); + filePath.mkdirs();// NOSONAR } else { //create directories for sub directories in zip File parentPathFile = filePath.getParentFile(); if (parentPathFile != null) { - parentPathFile.mkdirs(); + parentPathFile.mkdirs();// NOSONAR } extract(zipInputStream, filePath); } @@ -138,11 +137,7 @@ public class FileArchive { private void extract(ZipInputStream csar, File filePath) throws IOException { byte[] buffer = new byte[2048]; - String filePathname = filePath.getPath(); - if (!filePathname.startsWith(TEMP_DIR)) { - throw new IOException("Entry is outside of the target directory"); - } - try (FileOutputStream fos = new FileOutputStream(filePath); + try (FileOutputStream fos = new FileOutputStream(filePath);// NOSONAR BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length)) { int len; -- cgit 1.2.3-korg