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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.6.2

* Fixes the iOS/macOS crash when set negative video composition.

## 2.6.1

* Adds files to make include directory permanent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,14 @@ - (instancetype)initWithPlayerItem:(AVPlayerItem *)item
[self getVideoCompositionWithTransform:self->_preferredTransform
withAsset:asset
withVideoTrack:videoTrack];
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.

@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.

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.

}
}
};
[videoTrack loadValuesAsynchronouslyForKeys:@[ @"preferredTransform" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_avfoundation
description: iOS and macOS implementation of the video_player plugin.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.6.1
version: 2.6.2

environment:
sdk: ^3.2.3
Expand Down