-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
An infinite loop in function cv::dnn::readNetFromTensorflow() #22709
Description
System Information
OpenCV version: 4.6.0
Operating System / Platform: Ubuntu 22.04
Compiler & compiler version: gcc-11.3.0
Detailed description
We find an infinite loop when calling the function "cv::dnn::readNetFromTensorflow(input_file)". When the function read our input_file, it hangs and cannot terminate. We found that it stuck in a loop (located in cv::dnn::dnn4_v20220524::RemoveIdentityOps line 833-840 ). The vulnerable code is listed as follows:
while (true)
{
IdentityOpsMap::iterator nextIt = identity_ops.find(it->second);
if (nextIt != identity_ops.end())
it = nextIt;
else
break;
}By our debug, the iterator "nextIt" displayed as "nextIt = {first = "", second = ""}" as the loop execution, namely "first = second" in the map iterator. Once the map identity_ops.find(it->second) executed, "nextIt" will cyclically assigned by "", by which the loop cannot terminate.
Steps to reproduce
To reproduce the bug, only need to call the function readNetFromTensorflow(repo) by our reproduce file . The reproduce file repro. We triggered the bug by the following simple code:
#include <opencv2/dnn/dnn.hpp>
using namespace cv;
using namespace dnn;
int main(int argc, char* argv[]){
try {
readNetFromTensorflow((const char*)argv[1]);
} catch (std::exception &e) {}
return 1;
}Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)