Title: [242934] trunk
Revision
242934
Author
[email protected]
Date
2019-03-13 20:59:21 -0700 (Wed, 13 Mar 2019)

Log Message

Make -[_WKAttachment setFileWrapper:contentType:completion:] robust when given a nil completion handler
https://bugs.webkit.org/show_bug.cgi?id=195725
<rdar://problem/48545062>

Reviewed by Tim Horton.

Source/WebKit:

Add a missing nil check before invoking the given completionHandler in the case where the attachment is invalid.
Tested by augmenting WKAttachmentTests.SetFileWrapperForPDFImageAttachment to exercise this scenario.

* UIProcess/API/APIAttachment.cpp:
(API::Attachment::invalidate):

Additionally make sure that an invalidated _WKAttachment is also considered to be disconnected.

* UIProcess/API/Cocoa/_WKAttachment.mm:
(-[_WKAttachment setFileWrapper:contentType:completion:]):

Tools:

Test that we don't crash when changing the file wrapper of an invalid attachment, if the given completion
handler is nil.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (242933 => 242934)


--- trunk/Source/WebKit/ChangeLog	2019-03-14 03:07:40 UTC (rev 242933)
+++ trunk/Source/WebKit/ChangeLog	2019-03-14 03:59:21 UTC (rev 242934)
@@ -1,3 +1,22 @@
+2019-03-13  Wenson Hsieh  <[email protected]>
+
+        Make -[_WKAttachment setFileWrapper:contentType:completion:] robust when given a nil completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=195725
+        <rdar://problem/48545062>
+
+        Reviewed by Tim Horton.
+
+        Add a missing nil check before invoking the given completionHandler in the case where the attachment is invalid.
+        Tested by augmenting WKAttachmentTests.SetFileWrapperForPDFImageAttachment to exercise this scenario.
+
+        * UIProcess/API/APIAttachment.cpp:
+        (API::Attachment::invalidate):
+
+        Additionally make sure that an invalidated _WKAttachment is also considered to be disconnected.
+
+        * UIProcess/API/Cocoa/_WKAttachment.mm:
+        (-[_WKAttachment setFileWrapper:contentType:completion:]):
+
 2019-03-13  Timothy Hatcher  <[email protected]>
 
         REGRESSION (r242908):  'NSInvalidArgumentException', reason: '+[PKPaymentMerchantSession count]: unrecognized selector sent to class 0x1c0fae060'

Modified: trunk/Source/WebKit/UIProcess/API/APIAttachment.cpp (242933 => 242934)


--- trunk/Source/WebKit/UIProcess/API/APIAttachment.cpp	2019-03-14 03:07:40 UTC (rev 242933)
+++ trunk/Source/WebKit/UIProcess/API/APIAttachment.cpp	2019-03-14 03:59:21 UTC (rev 242934)
@@ -72,6 +72,7 @@
 #if PLATFORM(COCOA)
     m_fileWrapper.clear();
 #endif
+    m_insertionState = InsertionState::NotInserted;
 }
 
 #if !PLATFORM(COCOA)

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm (242933 => 242934)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm	2019-03-14 03:07:40 UTC (rev 242933)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm	2019-03-14 03:59:21 UTC (rev 242934)
@@ -123,7 +123,8 @@
 - (void)setFileWrapper:(NSFileWrapper *)fileWrapper contentType:(NSString *)contentType completion:(void (^)(NSError *))completionHandler
 {
     if (!_attachment->isValid()) {
-        completionHandler([NSError errorWithDomain:WKErrorDomain code:InvalidAttachmentErrorCode userInfo:nil]);
+        if (completionHandler)
+            completionHandler([NSError errorWithDomain:WKErrorDomain code:InvalidAttachmentErrorCode userInfo:nil]);
         return;
     }
 

Modified: trunk/Tools/ChangeLog (242933 => 242934)


--- trunk/Tools/ChangeLog	2019-03-14 03:07:40 UTC (rev 242933)
+++ trunk/Tools/ChangeLog	2019-03-14 03:59:21 UTC (rev 242934)
@@ -1,3 +1,17 @@
+2019-03-13  Wenson Hsieh  <[email protected]>
+
+        Make -[_WKAttachment setFileWrapper:contentType:completion:] robust when given a nil completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=195725
+        <rdar://problem/48545062>
+
+        Reviewed by Tim Horton.
+
+        Test that we don't crash when changing the file wrapper of an invalid attachment, if the given completion
+        handler is nil.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (TestWebKitAPI::TEST):
+
 2019-03-13  Sam Weinig  <[email protected]>
 
         Add utility function to allow easy reverse range-based iteration of a container

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (242933 => 242934)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2019-03-14 03:07:40 UTC (rev 242933)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2019-03-14 03:59:21 UTC (rev 242934)
@@ -1478,11 +1478,17 @@
     auto webView = webViewForTestingAttachments();
     [webView evaluateJavaScript:@"document.body.appendChild()" completionHandler:nil];
     NSString *identifier = [webView stringByEvaluatingJavaScript:@"const i = document.createElement('img'); document.body.appendChild(i); HTMLAttachmentElement.getAttachmentIdentifier(i)"];
-    _WKAttachment *attachment = [webView _attachmentForIdentifier:identifier];
+    auto attachment = retainPtr([webView _attachmentForIdentifier:identifier]);
 
     auto pdfFile = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testPDFData()]);
     [attachment setFileWrapper:pdfFile.get() contentType:(__bridge NSString *)kUTTypePDF completion:nil];
     [webView waitForImageElementSizeToBecome:CGSizeMake(130, 29)];
+
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+
+    auto zipFile = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testZIPData()]);
+    [attachment setFileWrapper:zipFile.get() contentType:(__bridge NSString *)kUTTypeZipArchive completion:nil];
+    EXPECT_FALSE([attachment isConnected]);
 }
 
 #pragma mark - Platform-specific tests
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to