[Common] check max tensor size limit
authorJaeyun <jy1210.jung@samsung.com>
Fri, 12 Oct 2018 05:48:39 +0000 (14:48 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Fri, 12 Oct 2018 07:31:37 +0000 (16:31 +0900)
update code to check array size limit, tensors max is now 16.

Related issue : #635

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
common/tensor_common.c

index 8970b05..1c429c2 100644 (file)
@@ -757,6 +757,11 @@ gst_tensors_config_from_structure (GstTensorsConfig * config,
     gst_structure_get_fraction (structure, "framerate", &config->rate_n,
         &config->rate_d);
 
+    if (config->info.num_tensors > NNS_TENSOR_SIZE_LIMIT) {
+      err_print ("Invalid param, max size is %d", NNS_TENSOR_SIZE_LIMIT);
+      config->info.num_tensors = NNS_TENSOR_SIZE_LIMIT;
+    }
+
     /* parse dimensions */
     dims_string = gst_structure_get_string (structure, "dimensions");
     if (dims_string) {
@@ -769,6 +774,10 @@ gst_tensors_config_from_structure (GstTensorsConfig * config,
       if (config->info.num_tensors != num_dims) {
         err_print ("Invalid param, dimensions (%d) tensors (%d)\n",
             num_dims, config->info.num_tensors);
+
+        if (num_dims > config->info.num_tensors) {
+          num_dims = config->info.num_tensors;
+        }
       }
 
       for (i = 0; i < num_dims; i++) {
@@ -790,6 +799,10 @@ gst_tensors_config_from_structure (GstTensorsConfig * config,
       if (config->info.num_tensors != num_types) {
         err_print ("Invalid param, types (%d) tensors (%d)\n",
             num_types, config->info.num_tensors);
+
+        if (num_types > config->info.num_tensors) {
+          num_types = config->info.num_tensors;
+        }
       }
 
       for (i = 0; i < num_types; i++) {