From e8ddb8424f0a6ecf0a1b46ca46f01872b6294bcd Mon Sep 17 00:00:00 2001 From: Murali Date: Fri, 13 Oct 2017 06:02:43 +0000 Subject: Bug:Fix file validation issue Change-Id: I3919c04312229c80fba1e5d4a02dfdd7536b81c5 Jira:VNFSDK-107 Signed-off-by: Murali --- .../onap/vnfsdk/marketplace/common/FileUtil.java | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'vnfmarket-be') diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java index 6a1efc45..a5ca6ac1 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java @@ -43,10 +43,12 @@ public final class FileUtil { private static final int BUFFER_SIZE = 2 * 1024 * 1024; + private static final int MAX_PACKAGE_SIZE = 50 * 1024 * 1024; + private static final int TRY_COUNT = 3; private FileUtil() { - // Empty constructor + // Empty constructor } /** @@ -268,14 +270,43 @@ public final class FileUtil { } public static boolean validateStream(FileInputStream ifs) { + + if (null == ifs) { + logger.error("File stream is null"); + return false; + } + + try { + if (false == ifs.getFD().valid()) { + logger.error("File descriptor is not valid"); + return false; + } + } catch (IOException e) { + logger.error("Exception while getting File descriptor", e); + } + return true; } public static boolean validatePath(String path) { + if (!new File(path).isDirectory()) { + logger.error("File is not a directory"); + return false; + } return true; } public static boolean validateFile(File fileData) { + if (null == fileData) { + logger.error("File data is null"); + return false; + } + + if (MAX_PACKAGE_SIZE < fileData.length()) { + logger.error("File size is greater than 50 MB", fileData.length()); + return false; + } + return true; } } -- cgit 1.2.3-korg