summaryrefslogtreecommitdiffstats
path: root/vnfmarket-be/vnf-sdk-marketplace
diff options
context:
space:
mode:
authorMurali <murali.p@huawei.com>2017-10-13 06:02:43 +0000
committerMurali <murali.p@huawei.com>2017-10-13 06:02:43 +0000
commite8ddb8424f0a6ecf0a1b46ca46f01872b6294bcd (patch)
tree5c14ad1c39d5a352daf4dc4b05b15f2c18ead4b8 /vnfmarket-be/vnf-sdk-marketplace
parent69a9d350fd9cf1d0f494ad9ebb8cd40dd18fb714 (diff)
Bug:Fix file validation issue
Change-Id: I3919c04312229c80fba1e5d4a02dfdd7536b81c5 Jira:VNFSDK-107 Signed-off-by: Murali <murali.p@huawei.com>
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace')
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java33
1 files changed, 32 insertions, 1 deletions
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;
}
}