⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243168 in webkit


Ignore:
Timestamp:
Mar 19, 2019, 1:35:14 PM (7 years ago)
Author:
Conrad Shultz
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(n2) process, but there typically are only a handful of types, so
this seems acceptable.
(-[WKFileUploadPanel _showDocumentPickerMenu]):
Convert the set from UTIsForMIMETypes() to an array.

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r243163 r243168  
     12019-03-19  Conrad Shultz  <conrad_shultz@apple.com>
     2
     3        REGRESSION (r242369): Only use picker-supported UTIs when creating image picker
     4        https://bugs.webkit.org/show_bug.cgi?id=195955
     5
     6        Reviewed by Chris Dumez and Wenson Hsieh.
     7
     8        r242369 started passing UTIs to -[UIImagePickerController setMediaTypes:] that correspond to types accepted by the
     9        file input element. However, UIImagePickerController expects a specific subset of UTIs. In the worst case, if no
     10        expected types are passed, this can cause a crash.
     11
     12        * UIProcess/ios/forms/WKFileUploadPanel.mm:
     13        (UTIsForMIMETypes):
     14        Return a set rather than an array.
     15        (-[WKFileUploadPanel _mediaTypesForPickerSourceType:]):
     16        Rather than hardcode specific UTIs, ask UIImagePickerController for its available types. If an accepted type
     17        is in the list of available types, use it. Otherwise, if an accepted type conforms to an available type,
     18        use the available type. This is an O(n^2) process, but there typically are only a handful of types, so
     19        this seems acceptable.
     20        (-[WKFileUploadPanel _showDocumentPickerMenu]):
     21        Convert the set from UTIsForMIMETypes() to an array.
     22
    1232019-03-19  Michael Catanzaro  <mcatanzaro@igalia.com>
    224
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm

    r242369 r243168  
    315315#pragma mark - Media Types
    316316
    317 static NSArray *UTIsForMIMETypes(NSArray *mimeTypes)
     317static NSSet<NSString *> *UTIsForMIMETypes(NSArray *mimeTypes)
    318318{
    319319    NSMutableSet *mediaTypes = [NSMutableSet set];
     
    323323            [mediaTypes addObject:(__bridge NSString *)uti];
    324324    }
    325     return mediaTypes.allObjects;
    326 }
    327 
    328 - (NSArray *)_mediaTypesForPickerSourceType:(UIImagePickerControllerSourceType)sourceType
    329 {
    330     NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get());
    331     if (mediaTypes.count)
     325    return mediaTypes;
     326}
     327
     328- (NSArray<NSString *> *)_mediaTypesForPickerSourceType:(UIImagePickerControllerSourceType)sourceType
     329{
     330    NSArray<NSString *> *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
     331    NSSet<NSString *> *acceptedMediaTypes = UTIsForMIMETypes(_mimeTypes.get());
     332    if (acceptedMediaTypes.count) {
     333        NSMutableArray<NSString *> *mediaTypes = [NSMutableArray array];
     334        for (NSString *availableMediaType in availableMediaTypes) {
     335            if ([acceptedMediaTypes containsObject:availableMediaType])
     336                [mediaTypes addObject:availableMediaType];
     337            else {
     338                for (NSString *acceptedMediaType in acceptedMediaTypes) {
     339                    if (UTTypeConformsTo((__bridge CFStringRef)acceptedMediaType, (__bridge CFStringRef)availableMediaType)) {
     340                        [mediaTypes addObject:availableMediaType];
     341                        break;
     342                    }
     343                }
     344            }
     345        }
    332346        return mediaTypes;
     347    }
    333348
    334349    // Fallback to every supported media type if there is no filter.
    335     return [UIImagePickerController availableMediaTypesForSourceType:sourceType];
     350    return availableMediaTypes;
    336351}
    337352
     
    357372- (void)_showDocumentPickerMenu
    358373{
    359     NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get());
     374    NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get()).allObjects;
    360375
    361376    BOOL containsImageMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeImage);
Note: See TracChangeset for help on using the changeset viewer.