wordpress-mobile / MediaPicker-iOS

WPMediaPicker is an iOS controller that allows capture and picking of media assets.
GNU General Public License v2.0
110 stars 37 forks source link

NSInvalidArgumentException: optional property accessed in -[WPMediaCollectionViewCell configureAccessibility] without checking for conformance #371

Closed joshheald closed 3 years ago

joshheald commented 3 years ago

Describe the bug A low-incidence crash in the WooCommerce app was found, caused by an NSInvalidArgumentException -[WooCommerce.CancellableMedia filename]: unrecognized selector sent to instance.

filename an @optional property on the WPMediaAsset Objective-C protocol definition, along with fileExtension and UTTypeIdentifier.

This was found to be called from the -[WPMediaCollectionViewCell configureAccessibility] method, for documents, without first checking for respondsToSelector:, causing a crash where users have assets other than images, video, or audio, in their Media Library.

Unable to reproduce at present – there is likely a very uncommon corner case leading to this crash in the WooCommerce app, because all the uses of MediaPicker-iOS in the app are currently filtered to show images only.

To reproduce, I would suggest invoking the picker without a filetype filter, using an asset implementation which does not include filename, on a site with a document. It probably requires a demo app to repro reliably.

Expected behavior The app should not crash when a document is present in the media library, even if filename is unimplemented on the asset implementation.