Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[video_player] Fix appleos crash when set negative video composition #7050

Conversation

lxhlzyh
Copy link

@lxhlzyh lxhlzyh commented Jul 3, 2024

iOS/macOS crash when set negative video composition, we should catch this exception.

Fixes flutter/flutter#151031

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link

google-cla bot commented Jul 3, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

  • I added new tests to check the change I am making, or this PR is test-exempt.

Where is this new test?

item.videoComposition = videoComposition;
// Invalid values of video composition will throws an exception
// (https://github.com/flutter/flutter/issues/151031).
// When there is a problem with the parameters of video composition, set nil.
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the invalid video composition value coming from? If it's user input, this is very late in the code to be enforcing anything about it.

// When there is a problem with the parameters of video composition, set nil.
@try {
item.videoComposition = videoComposition;
} @catch (NSException *exception) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless it's impossible to know in advance that a value is invalid for some reason, creating an exception and then catching it is not correct behavior. Invalid arguments are a programming error, not a runtime error, so the plugin code should never be calling this with invalid arguments in the first place.

Copy link
Author

@lxhlzyh lxhlzyh Jul 4, 2024

Choose a reason for hiding this comment

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

In this plugin, invalid parameters may be caused by renderSize of videoCompositiom, but there are multiple cases in the documentation. However if we know that the parameter is abnormal, should we still let it be created successfully? I don't think setting invalid videoComposition is necessary for the creation process.

Copy link
Author

Choose a reason for hiding this comment

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

However, we should check the validity of videoComposition in this function. Still, we want to determine if the creation process should be interrupted.

- (AVMutableVideoComposition *)getVideoCompositionWithTransform:(CGAffineTransform)transform

Copy link
Contributor

Choose a reason for hiding this comment

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

there are multiple cases in the documentation

Please provide a link to the documentation that you are referring to here, so that we are all working from the same information.

However if we know that the parameter is abnormal, should we still let it be created successfully? I don't think setting invalid videoComposition is necessary for the creation process.

Please see my other unanswered question about whether the invalid values are coming from. Until there's an answer to that, there's no way to answer questions about how they should be handled. Bad values that come from plugin clients are very different from bad values that come from uncontrolled external video date, both of which are very different from bad values coming from a programming error in the plugin itself.

@try {
item.videoComposition = videoComposition;
} @catch (NSException *exception) {
item.videoComposition = nil;
Copy link
Contributor

Choose a reason for hiding this comment

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

Errors, especially if they are ultimately caused by input from plugin clients, should never be silently ignored.

Copy link
Author

Choose a reason for hiding this comment

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

I agree, as i said earlier, if we know that the parameter is abnormal, should we still let it be created successfully? If the creation process is to continue, there should be no other way than to set fake data and not set it at all. Or just return an error back to flutter?

Copy link
Contributor

Choose a reason for hiding this comment

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

As above; we cannot answer this question without more information about the cause of the error.

@lxhlzyh
Copy link
Author

lxhlzyh commented Jul 4, 2024

Thanks for the contribution!

  • I added new tests to check the change I am making, or this PR is test-exempt.

Where is this new test?
The problem was found in the crash log report, so there was no video source to write a replay test, I don't know what kind of test to write.

@stuartmorgan
Copy link
Contributor

stuartmorgan commented Jul 6, 2024

The problem was found in the crash log report, so there was no video source to write a replay test, I don't know what kind of test to write.

If we don't know enough to construct a plausible test case that would reproduce the exception in a test, then we don't know enough to fix the issue.

If we do, then then the test should do that.

Either way, please don't check a checkbox for something you haven't actually done, as it makes things more difficult for reviewers. The checklist should reflect the actual state of the PR.

@lxhlzyh
Copy link
Author

lxhlzyh commented Jul 8, 2024

The problem was found in the crash log report, so there was no video source to write a replay test, I don't know what kind of test to write.

If we don't know enough to construct a plausible test case that would reproduce the exception in a test, then we don't know enough to fix the issue.

If we do, then then the test should do that.

Either way, please don't check a checkbox for something you haven't actually done, as it makes things more difficult for reviewers. The checklist should reflect the actual state of the PR.

Thank you, i miss something.

@stuartmorgan
Copy link
Contributor

From triage: @lxhlzyh are you still planning on updating this PR per the discussion above?

@stuartmorgan
Copy link
Contributor

Thank you for your contribution. I'm going to close this PR for now since there are outstanding comments, just to get this off our PR review queue. Please don't hesitate to submit a new PR if you have the time to address the review comments. Thanks!

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.

[video_player]Invalid videoComposition may cause the app crash
2 participants