[locomotiv] Prevent input/output index overflow (#4286)
author박천교/On-Device Lab(SR)/Engineer/삼성전자 <ch.bahk@samsung.com>
Tue, 16 Jul 2019 07:24:31 +0000 (16:24 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Tue, 16 Jul 2019 07:24:31 +0000 (16:24 +0900)
This commit make assertion on input and output index to be less than
their size.

Signed-off-by: Cheongyo Bahk <ch.bahk@samsung.com>
contrib/locomotiv/src/Session.cpp

index 8e64d1c..cde38dd 100644 (file)
@@ -21,6 +21,8 @@
 #include "NodeExecution.h"
 #include "NodeDomain.h"
 
+#include <cassert>
+
 namespace locomotiv
 {
 
@@ -36,6 +38,8 @@ Session::~Session()
 
 void Session::set_input(uint32_t index, std::unique_ptr<NodeData> &&data)
 {
+  assert(index < input_size());
+
   // Check whether already annotated
   auto pull = _graph->inputs()->at(index)->node();
   if (annot_data(pull))
@@ -85,6 +89,8 @@ void Session::infer()
 
 const NodeData *Session::get_output(uint32_t index)
 {
+  assert(index < output_size());
+
   auto output_node = _graph->outputs()->at(index)->node();
   return annot_data(output_node);
 }