Title: [243168] trunk/Source/WebKit
Revision
243168
Author
conrad_shu...@apple.com
Date
2019-03-19 13:35:14 -0700 (Tue, 19 Mar 2019)

Log Message

REGRESSION (r242369): Only use picker-supported UTIs when creating image picker
https://bugs.webkit.org/show_bug.cgi?id=195955

Reviewed by Chris Dumez and Wenson Hsieh.

r242369 started passing UTIs to -[UIImagePickerController setMediaTypes:] that correspond to types accepted by the
file input element. However, UIImagePickerController expects a specific subset of UTIs. In the worst case, if no
expected types are passed, this can cause a crash.

* UIProcess/ios/forms/WKFileUploadPanel.mm:
(UTIsForMIMETypes):
Return a set rather than an array.
(-[WKFileUploadPanel _mediaTypesForPickerSourceType:]):
Rather than hardcode specific UTIs, ask UIImagePickerController for its available types. If an accepted type
is in the list of available types, use it. Otherwise, if an accepted type conforms to an available type,
use the available type. This is an O(n^2) process, but there typically are only a handful of types, so
this seems acceptable.
(-[WKFileUploadPanel _showDocumentPickerMenu]):
Convert the set from UTIsForMIMETypes() to an array.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (243167 => 243168)


--- trunk/Source/WebKit/ChangeLog	2019-03-19 20:27:51 UTC (rev 243167)
+++ trunk/Source/WebKit/ChangeLog	2019-03-19 20:35:14 UTC (rev 243168)
@@ -1,3 +1,25 @@
+2019-03-19  Conrad Shultz  <conrad_shu...@apple.com>
+
+        REGRESSION (r242369): Only use picker-supported UTIs when creating image picker
+        https://bugs.webkit.org/show_bug.cgi?id=195955
+
+        Reviewed by Chris Dumez and Wenson Hsieh.
+
+        r242369 started passing UTIs to -[UIImagePickerController setMediaTypes:] that correspond to types accepted by the
+        file input element. However, UIImagePickerController expects a specific subset of UTIs. In the worst case, if no
+        expected types are passed, this can cause a crash.
+
+        * UIProcess/ios/forms/WKFileUploadPanel.mm:
+        (UTIsForMIMETypes):
+        Return a set rather than an array.
+        (-[WKFileUploadPanel _mediaTypesForPickerSourceType:]):
+        Rather than hardcode specific UTIs, ask UIImagePickerController for its available types. If an accepted type
+        is in the list of available types, use it. Otherwise, if an accepted type conforms to an available type,
+        use the available type. This is an O(n^2) process, but there typically are only a handful of types, so
+        this seems acceptable.
+        (-[WKFileUploadPanel _showDocumentPickerMenu]):
+        Convert the set from UTIsForMIMETypes() to an array.
+
 2019-03-19  Michael Catanzaro  <mcatanz...@igalia.com>
 
         Build cleanly with GCC 9

Modified: trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm (243167 => 243168)


--- trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm	2019-03-19 20:27:51 UTC (rev 243167)
+++ trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm	2019-03-19 20:35:14 UTC (rev 243168)
@@ -314,7 +314,7 @@
 
 #pragma mark - Media Types
 
-static NSArray *UTIsForMIMETypes(NSArray *mimeTypes)
+static NSSet<NSString *> *UTIsForMIMETypes(NSArray *mimeTypes)
 {
     NSMutableSet *mediaTypes = [NSMutableSet set];
     for (NSString *mimeType in mimeTypes) {
@@ -322,17 +322,32 @@
         if (!uti.isEmpty())
             [mediaTypes addObject:(__bridge NSString *)uti];
     }
-    return mediaTypes.allObjects;
+    return mediaTypes;
 }
 
-- (NSArray *)_mediaTypesForPickerSourceType:(UIImagePickerControllerSourceType)sourceType
+- (NSArray<NSString *> *)_mediaTypesForPickerSourceType:(UIImagePickerControllerSourceType)sourceType
 {
-    NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get());
-    if (mediaTypes.count)
+    NSArray<NSString *> *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
+    NSSet<NSString *> *acceptedMediaTypes = UTIsForMIMETypes(_mimeTypes.get());
+    if (acceptedMediaTypes.count) {
+        NSMutableArray<NSString *> *mediaTypes = [NSMutableArray array];
+        for (NSString *availableMediaType in availableMediaTypes) {
+            if ([acceptedMediaTypes containsObject:availableMediaType])
+                [mediaTypes addObject:availableMediaType];
+            else {
+                for (NSString *acceptedMediaType in acceptedMediaTypes) {
+                    if (UTTypeConformsTo((__bridge CFStringRef)acceptedMediaType, (__bridge CFStringRef)availableMediaType)) {
+                        [mediaTypes addObject:availableMediaType];
+                        break;
+                    }
+                }
+            }
+        }
         return mediaTypes;
+    }
 
     // Fallback to every supported media type if there is no filter.
-    return [UIImagePickerController availableMediaTypesForSourceType:sourceType];
+    return availableMediaTypes;
 }
 
 #pragma mark - Source selection menu
@@ -356,7 +371,7 @@
 
 - (void)_showDocumentPickerMenu
 {
-    NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get());
+    NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get()).allObjects;
 
     BOOL containsImageMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeImage);
     BOOL containsVideoMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeMovie);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to