From 18fbb72f7db0728a178110b3c7d8bbaba5c8abad Mon Sep 17 00:00:00 2001 From: Zihao Mu Date: Mon, 31 Oct 2022 20:10:25 +0800 Subject: [PATCH] fix the infinite loop in tf importer. --- modules/dnn/src/tensorflow/tf_graph_simplifier.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp b/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp index 72f546ead9..25ef850417 100644 --- a/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp +++ b/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp @@ -829,12 +829,19 @@ void RemoveIdentityOps(tensorflow::GraphDef& net) IdentityOpsMap::iterator it = identity_ops.find(input_op_name); if (it != identity_ops.end()) { + std::set loopCheckSet; // In case of Identity after Identity while (true) { IdentityOpsMap::iterator nextIt = identity_ops.find(it->second); if (nextIt != identity_ops.end()) + { + // Loop check + if (loopCheckSet.find(it->second) != loopCheckSet.end()) + CV_Error(Error::StsError, "Found a loop in your input Tensorflow model, which is illegal!"); + loopCheckSet.insert(it->second); it = nextIt; + } else break; }