[C-Api/Single] validate input data
authorJaeyun <jy1210.jung@samsung.com>
Wed, 10 Jul 2019 08:23:33 +0000 (17:23 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Thu, 11 Jul 2019 22:15:54 +0000 (07:15 +0900)
Add code to validate input data in single-invoke function.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
api/capi/src/nnstreamer-capi-single.c

index 2ae92b7..e678490 100644 (file)
@@ -362,6 +362,21 @@ ml_single_invoke (ml_single_h single,
   single_h = (ml_single *) single;
   in_data = (ml_tensors_data_s *) input;
 
+  /* Validate input data */
+  if (in_data->num_tensors != single_h->in_info.num_tensors) {
+    ml_loge ("The given param input is invalid, different number of memory blocks.");
+    return ML_ERROR_INVALID_PARAMETER;
+  }
+
+  for (i = 0; i < in_data->num_tensors; i++) {
+    size_t raw_size = ml_tensor_info_get_size (&single_h->in_info.info[i]);
+
+    if (!in_data->tensors[i].tensor || in_data->tensors[i].size != raw_size) {
+      ml_loge ("The given param input is invalid, different size of memory block.");
+      return ML_ERROR_INVALID_PARAMETER;
+    }
+  }
+
   /* Allocate output buffer */
   status = ml_tensors_data_create (&single_h->out_info, output);
   if (status != ML_ERROR_NONE) {