Bug:Fix file validation issue 03/18703/1
authorMurali <murali.p@huawei.com>
Fri, 13 Oct 2017 06:02:43 +0000 (06:02 +0000)
committerMurali <murali.p@huawei.com>
Fri, 13 Oct 2017 06:02:43 +0000 (06:02 +0000)
Change-Id: I3919c04312229c80fba1e5d4a02dfdd7536b81c5
Jira:VNFSDK-107
Signed-off-by: Murali <murali.p@huawei.com>
vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java

index 6a1efc4..a5ca6ac 100644 (file)
@@ -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;
        }
 }