Skip to content

Fix gst error handling#20801

Merged
alalek merged 2 commits intoopencv:3.4from
JonasVautherin:fix-gst-error-handling
Oct 8, 2021
Merged

Fix gst error handling#20801
alalek merged 2 commits intoopencv:3.4from
JonasVautherin:fix-gst-error-handling

Conversation

@JonasVautherin
Copy link
Copy Markdown
Contributor

@JonasVautherin JonasVautherin commented Oct 3, 2021

@alalek: similar to #20796. I think I have found a case where somebody had an issue with one of those bugs: https://stackoverflow.com/questions/61394756/how-to-use-opencv-videowriter-with-gstreamer 🙂

  • Use the return value instead of the error, which gives no guarantee of being NULL in case of error
  • Test err pointer before accessing it
  • Remove unreachable code

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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
force_builders=Linux AVX2,Custom
build_image:Custom=gstreamer:14.04
buildworker:Custom=linux-4

* Use the return value instead of the error, which gives no guarantee of being NULL in case of error
* Test err pointer before accessing it
* Remove unreachable code
GSafePtr<GError> err;
uridecodebin.attach(gst_parse_launch(filename, err.getRef()));
if (err)
if (!uridecodebin)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the actual bug: nothing guarantees that err will be NULL if gst_parse_launch fails. But uridecodebin will be NULL for sure in case of failure.


if (manualpipeline)
{
if (err)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This code is at best unreachable (if we reach this line, it means that manualpipeline is true, and hence it means that gst_parse_launch above did not fail), and at worst it triggers an error because gst_parse_launch does not guarantee err to be NULL if it succeeds.

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.

Our "bad" tests are fails and hangs with that change.

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Thank you 👍

To be merged without fix in writer.

@alalek alalek merged commit 9537a90 into opencv:3.4 Oct 8, 2021
@JonasVautherin JonasVautherin deleted the fix-gst-error-handling branch October 8, 2021 06:23
@alalek alalek mentioned this pull request Oct 8, 2021
@alalek alalek mentioned this pull request Oct 15, 2021
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.

2 participants