Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix potential READ memory access#26782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
asmorkalov merged 3 commits intoopencv:4.xfromvrabaud:png_leak
Jan 22, 2025
Merged

Conversation

@vrabaud
Copy link
Contributor

@vrabaudvrabaud commentedJan 16, 2025
edited
Loading

This fixeshttps://oss-fuzz.com/testcase-detail/4923671881252864 andhttps://oss-fuzz.com/testcase-detail/5048650127966208

Pull Request Readiness Checklist

See details athttps://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
  • 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

@vrabaud
Copy link
ContributorAuthor

vrabaud commentedJan 16, 2025
edited
Loading

@asmorkalov, I see that tests are failing due to old GitHub dependencies. We probably want a dependabot config. This is what we have for AVIF:https://github.com/AOMediaCodec/libavif/blob/main/.github/dependabot.yml

It will make PRs once a month to update your CI files (if needed)

@warped-rudi
Copy link
Contributor

@vrabaud Can you elaborate on this a bit more? IMHO there is nothing wrong with the original code.

@asmorkalov
Copy link
Contributor

@vrabaud Could you bring more details. I do not see any difference.

@vrabaudvrabaud changed the titleUse a proper move functionFix potential READ memory accessJan 20, 2025
@vrabaud
Copy link
ContributorAuthor

My code was wrong, the new one works. Temporary variables do not play well withsetjmp ...

asmorkalov reacted with thumbs up emoji

@asmorkalovasmorkalov self-assigned thisJan 20, 2025
@asmorkalovasmorkalov added this to the4.12.0 milestoneJan 20, 2025
@warped-rudi
Copy link
Contributor

It's still a bit inconsistent to me. I'm aware that setjmp/longjmp has the potential to bypass destructors (and thereby causing memory leaks) in certain situations. If this is a problem in 'processing_start' (not sure if it is), wouldn't 'readHeader' suffer from the same issue? So I think either local 'PngPtrs' should be avoided in both cases or in none of them. Also, if we go the route of working directly with 'm_png_ptrs', we should probably clear it in case of failures. Like it is done in 'processing_finish'.

@warped-rudi
Copy link
Contributor

There is another small thing I find unfortunate: The default constructor of 'PngPtrs' allocates data. That means, when a PngDecoder is instantiated, we allocate stuff that gets thrown away on the very first usage of this decoder instance. I guess it's better to add an explicit 'init' method to 'PngPtrs' and let the default constructor just zero-initialize all member variables.

@vrabaudvrabaudforce-pushed thepng_leak branch 2 times, most recently from786603f to7a9f2cdCompareJanuary 21, 2025 12:24
@vrabaud
Copy link
ContributorAuthor

@warped-rudi , I indeed refactored to be more consistent. The READ memory access is fixed by the extrasetjmp in readData`.

warped-rudi reacted with thumbs up emoji

@vrabaudvrabaudforce-pushed thepng_leak branch 2 times, most recently from3c6af8f tod7be006CompareJanuary 21, 2025 14:51
@vrabaud
Copy link
ContributorAuthor

@warped-rudi
Copy link
Contributor

warped-rudi commentedJan 22, 2025
edited
Loading

That look good to me! Two more nit-picks: PngDecoder (as well as PngEncoder) don't have to have protected members. Make them private. Also the question wether or not to call ClearPngPtr() every time setjmp() returns a non-zero value persists. Currently it's only done in processing_finish().

@asmorkalov
Copy link
Contributor

Linux builds report:

/home/ci/opencv/modules/imgcodecs/src/grfmt_png.cpp:540:21: warning: variable 'buffer' might be clobbered by 'longjmp' or 'vfork' [-Wclobbered]

@vrabaud
Copy link
ContributorAuthor

I fixed the two comments.

That look good to me! Two more nit-picks: PngDecoder (as well as PngEncoder) don't have to have protected members. Make them private. Also the question wether or not to call ClearPngPtr() every time setjmp() returns a non-zero value persists. Currently it's only done in processing_finish().

ClearPngPtr does not need to be called every time setjmp returns a non-zero as it deals with variables outside of the longjmp. Those variables will be cleared normally by the destructor. I removed it from processing_finish.

asmorkalov reacted with thumbs up emoji

@asmorkalovasmorkalov merged commit7728dd3 intoopencv:4.xJan 22, 2025
30 of 31 checks passed
@asmorkalovasmorkalov mentioned this pull requestFeb 19, 2025
NanQin555 pushed a commit to NanQin555/opencv that referenced this pull requestFeb 24, 2025
Fix potential READ memory accessopencv#26782This fixeshttps://oss-fuzz.com/testcase-detail/4923671881252864 andhttps://oss-fuzz.com/testcase-detail/5048650127966208### Pull Request Readiness ChecklistSee details athttps://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- [ ] 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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@asmorkalovasmorkalovasmorkalov approved these changes

Assignees

@asmorkalovasmorkalov

Projects

None yet

Milestone

4.12.0

Development

Successfully merging this pull request may close these issues.

3 participants

@vrabaud@warped-rudi@asmorkalov

[8]ページ先頭

©2009-2025 Movatter.jp