From 2ff16d4c45b122bef659eee4b0ee2fa970b3bfae Mon Sep 17 00:00:00 2001 From: Laurent Berger <3591626+LaurentBerger@users.noreply.github.com> Date: Fri, 4 Aug 2023 11:18:49 +0200 Subject: [PATCH] Merge pull request #24101 from LaurentBerger:I24076 Invalid memory access fix for ONNX split layer parser #24076 #24101 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work https://github.com/opencv/opencv/issues/24076 - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake --- modules/dnn/src/onnx/onnx_importer.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 68769712ac..24e8b3f913 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -1385,13 +1385,19 @@ void ONNXImporter::parseSplit(LayerParams& layerParams, const opencv_onnx::NodeP CV_Assert(constBlobs.find(node_proto.input(1)) != constBlobs.end()); Mat splitsBlob = getBlob(node_proto, 1); int splitSize = splitsBlob.total(); - - std::vector slicePoints(splitSize - 1, splitsBlob.at(0)); - for (int i = 1; i < splitSize - 1; ++i) + if (splitSize == 1) + { + layerParams.set("num_split", 1); + } + else { - slicePoints[i] = slicePoints[i - 1] + splitsBlob.at(i); + std::vector slicePoints(splitSize - 1, splitsBlob.at(0)); + for (int i = 1; i < splitSize - 1; ++i) + { + slicePoints[i] = slicePoints[i - 1] + splitsBlob.at(i); + } + layerParams.set("slice_point", DictValue::arrayInt(&slicePoints[0], slicePoints.size())); } - layerParams.set("slice_point", DictValue::arrayInt(&slicePoints[0], slicePoints.size())); } else {