Fix vector access in TF::sortByExecutionOrder#22006
Fix vector access in TF::sortByExecutionOrder#22006opencv-pushbot merged 1 commit intoopencv:3.4from
Conversation
| } | ||
| else | ||
| numRefsToAdd[i] = numInputsInGraph; | ||
| numRefsToAdd.at(i) = numInputsInGraph; |
There was a problem hiding this comment.
.at() emits on error:
C++ exception with description "vector::_M_range_check: __n (which is 10) >= this->size() (which is 1)" thrown in the test body.
OpenCV check (before if (node.op() == "Merge" ...)
CV_CheckLT((size_t)i, numRefsToAdd.size(), "");
could emit message with line number from OpenCV codebase.
C++ exception with description "OpenCV(3.4.17-dev) modules/dnn/src/tensorflow/tf_graph_simplifier.cpp:1018: error: (-2:Unspecified error) in function 'void cv::dnn::experimental_dnn_34_v24::sortByExecutionOrder(opencv_tensorflow::GraphDef&)'
> (expected: '(size_t)i < numRefsToAdd.size()'), where
> '(size_t)i' is 10
> must be less than
> 'numRefsToAdd.size()' is 1
" thrown in the test body.
If user comes with report with the first message only then it would be bad for problem investigation (we need to start from beginning and ask for debugger and its call trace to confirm the problem).
.at() is harmless in importer code (until we have problems with importer performance), but IMHO, it is for lazy developers who don't add code for validation of input.
BTW, ENABLE_GNU_STL_DEBUG / _GLIBCXX_DEBUG (which enables debug checks including [i] case) causes crashes inside of protobuf code. Perhaps something is broken (e.g. modifying of protobuf nodes)
Accurate check looks like
CV_CheckEQ(nodesMap.size(), (size_t)net.node_size(), "node names must be unique");
after the first for loop (line 992).
Merge with extra: opencv/opencv_extra#974
Fixes #21947
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.