Add file extension check before adding image file to set home or lock screen
[platform/core/api/system-settings.git] / src / sst_utils_wrapper.c
index e0539e9..5b0c822 100644 (file)
@@ -16,6 +16,7 @@
 #include "sst_utils_wrapper.h"
 
 #include <dlfcn.h>
+#include <string.h>
 #include "sst.h"
 #include "sst_misc.h"
 
@@ -103,7 +104,23 @@ char* sstu_get_default_font()
 
 bool sstu_is_valid_image(const char *path)
 {
-    return sst_misc_file_exists(path);
+       if (!sst_misc_file_exists(path))
+               return false;
+
+       char *ext_list[10] = {"jif", "jfif", "jpe", "jpeg", "jpg",
+                                                       "bmp", "dib", "gif", "png", "webp",
+                                                       };
+       char *filename = strrchr(path, '/');
+       if (NULL == filename || NULL == filename + 1)
+               return false;
+       char *ext = strrchr(filename + 1, '.');
+       if (NULL == ext || NULL == ext + 1)
+               return false;
+       for (int i =  0; i < 10; i++) {
+               if (!strcmp(ext + 1, ext_list[i]))
+                       return true;
+       }
+       return false;
 }
 void sstu_set_font_size()
 {