[Python] validate tensors info
authorJaeyun Jung <jy1210.jung@samsung.com>
Wed, 1 Nov 2023 06:49:06 +0000 (15:49 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 6 Nov 2023 10:51:35 +0000 (19:51 +0900)
Validate output tensors info after parsing pyobject.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
ext/nnstreamer/extra/nnstreamer_python3_helper.cc

index c8f730e..b2abc06 100644 (file)
@@ -484,6 +484,15 @@ parseTensorsInfo (PyObject *result, GstTensorsInfo *info)
     Py_SAFEDECREF (shape_dims);
   }
 
+  /* Validate output tensors info after parsing python object. */
+  if (!gst_tensors_info_validate (info)) {
+    gchar *info_str = gst_tensors_info_to_string (info);
+    Py_ERRMSG ("Failed to parse the tensors information from python script, it may include invalid tensor type or dimension value (%s).",
+        info_str);
+    g_free (info_str);
+    return -EINVAL;
+  }
+
   return 0;
 }