Skip to content

Invalid memory access fix for ONNX split layer parser #24076#24101

Merged
asmorkalov merged 2 commits intoopencv:4.xfrom
LaurentBerger:I24076
Aug 4, 2023
Merged

Invalid memory access fix for ONNX split layer parser #24076#24101
asmorkalov merged 2 commits intoopencv:4.xfrom
LaurentBerger:I24076

Conversation

@LaurentBerger
Copy link
Copy Markdown
Contributor

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work Exception in ONNX::parseSplit  #24076
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@asmorkalov asmorkalov changed the title Issue 24076 Invalid memory access fix for ONNX split layer parser #24076 Aug 3, 2023
@asmorkalov asmorkalov added this to the 4.9.0 milestone Aug 3, 2023
slicePoints[i] = slicePoints[i - 1] + splitsBlob.at<int>(i);
}
layerParams.set("slice_point", DictValue::arrayInt(&slicePoints[0], slicePoints.size()));
if (slicePoints.size() == 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check splitSize earlier:

int splitSize = splitsBlob.total();

if (splitSize == 1)
{
    layerParams.set("num_split", 1);
}
else
{
    std::vector<int> slicePoints(splitSize - 1, splitsBlob.at<int>(0));
    for (int i = 1; i < splitSize - 1; ++i)
    {
        slicePoints[i] = slicePoints[i - 1] + splitsBlob.at<int>(i);
    }
    layerParams.set("slice_point", DictValue::arrayInt(&slicePoints[0], slicePoints.size()));
}

slicePoints[i] = slicePoints[i - 1] + splitsBlob.at<int>(i);
}
layerParams.set("slice_point", DictValue::arrayInt(&slicePoints[0], slicePoints.size()));
if (slicePoints.size() == 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slicePoints.empty() is better IMHO.

@dkurt dkurt linked an issue Aug 4, 2023 that may be closed by this pull request
4 tasks
@dkurt dkurt requested a review from fengyuentau August 4, 2023 07:40
Copy link
Copy Markdown
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case split as attribute shares the same code. Is it possible to reduce duplicates? E.g. using lamda expressions?

auto fn = [&] (const vector<int> &splits) {
  if (splits.size() == 1) {
    // ...
  } else {
    // ...
  }
}

@asmorkalov asmorkalov merged commit 2ff16d4 into opencv:4.x Aug 4, 2023
@asmorkalov asmorkalov mentioned this pull request Aug 7, 2023
@LaurentBerger LaurentBerger deleted the I24076 branch August 10, 2023 02:42
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Invalid memory access fix for ONNX split layer parser opencv#24076 opencv#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 opencv#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
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Invalid memory access fix for ONNX split layer parser opencv#24076 opencv#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 opencv#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception in ONNX::parseSplit

4 participants