From d5f73f89d87f4f87a19e1b657c7c65b9231644a6 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Thu, 13 Jan 2022 00:13:59 +0300 Subject: [PATCH] Fixed issues found by static analysis --- modules/dnn/src/onnx/onnx_importer.cpp | 11 +++++++++++ modules/gapi/src/api/media.cpp | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index a2b28462e8..0a691913a8 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -1188,6 +1188,7 @@ void ONNXImporter::parseSlice(LayerParams& layerParams, const opencv_onnx::NodeP CV_Assert(starts.size() == ends.size()); if (axis > 0) { + CV_CheckLE(axis, 1024, "Slice layer can't have more than 1024 axes"); // arbitrary limit begin.resize(axis, 0); end.resize(axis, -1); } @@ -1470,6 +1471,13 @@ void ONNXImporter::parseLSTM(LayerParams& layerParams, const opencv_onnx::NodePr const int numDirs = Wx.size[0]; // Is 1 for forward only and 2 for bidirectional LSTM. const int numFeatures = Wx.size[2]; + // Following checks are deduced from the IFGO->IGFO loop below + // Wx is numDirs X numHidden*3 X numFeatures + // Wh is numDirs X numHidden*3 X numHidden + CV_CheckLE(numHidden * 3, Wx.size[1], "Wx should have beat least 3x hidden_size in dimension 1"); + CV_CheckLE(numHidden * 3, Wh.size[1], "Wh should have be at least 3x hidden_size in dimension 1"); + CV_CheckLE(numHidden, Wh.size[2], "Wh should have be at least hidden_size in dimension 2"); + Mat h0, c0; if (!node_proto.input(5).empty()) { h0 = getBlob(node_proto, 5); @@ -1491,6 +1499,9 @@ void ONNXImporter::parseLSTM(LayerParams& layerParams, const opencv_onnx::NodePr Mat bh = b.colRange(b.cols / 2, b.cols); b = bx + bh; + // b is numDirs X numHidden*3 + CV_CheckLE(numHidden * 3, b.cols, "Bias data should have at least 3x hidden_size columns"); + // IFGO->IGFO for (int k = 0; k < numDirs; ++k) { diff --git a/modules/gapi/src/api/media.cpp b/modules/gapi/src/api/media.cpp index b1c455d40a..a3643e378c 100644 --- a/modules/gapi/src/api/media.cpp +++ b/modules/gapi/src/api/media.cpp @@ -36,7 +36,7 @@ cv::MediaFrame::IAdapter* cv::MediaFrame::getAdapter() const { } void cv::MediaFrame::serialize(cv::gapi::s11n::IOStream& os) const { - return m->adapter->serialize(os); + m->adapter->serialize(os); } cv::MediaFrame::View::View(Ptrs&& ptrs, Strides&& strs, Callback &&cb) -- GitLab