Changeset 268904 in webkit
- Timestamp:
- Oct 22, 2020, 9:25:13 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/platform/PlatformStrategies.cpp (modified) (1 diff)
-
Source/WebCore/platform/PlatformStrategies.h (modified) (1 diff)
-
Source/WebCore/platform/network/FormData.cpp (modified) (1 diff)
-
Source/WebCore/platform/network/FormData.h (modified) (1 diff)
-
Source/WebCore/platform/network/cf/FormDataStreamCFNet.cpp (modified) (2 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/NavigationAction.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r268902 r268904 1 2020-10-22 Alex Christensen <achristensen@webkit.org> 2 3 Null check platformStrategies when making blob read stream for an NSURLRequest 4 https://bugs.webkit.org/show_bug.cgi?id=218112 5 <rdar://problem/70507102> 6 7 Reviewed by Wenson Hsieh. 8 9 r266187 made it possible to create a DataTransfer without a user event, which allows you to make a FileList, 10 which allows you to submit a multipart form without a user event that calls decidePolicyForNavigationAction 11 with a request that has a form data body that would make a blob upload stream. This causes us to use 12 platformStrategies in the UI process, which dereferences null. Since the blob only really exists in the network 13 process, just return a nil HTTPBody in such an exotic case instead of crashing. 14 15 Covered by an API test that would hit this crash. Web platform tests were insufficient because WebKitTestRunner does not 16 access WKNavigationAction.request, but Safari does. 17 18 * platform/PlatformStrategies.cpp: 19 (WebCore::hasPlatformStrategies): 20 * platform/PlatformStrategies.h: 21 * platform/network/FormData.cpp: 22 (WebCore::FormData::containsBlobElement const): 23 (WebCore::FormData::resolveBlobReferences): 24 * platform/network/FormData.h: 25 * platform/network/cf/FormDataStreamCFNet.cpp: 26 (WebCore::createHTTPBodyCFReadStream): 27 1 28 2020-10-22 Simon Fraser <simon.fraser@apple.com> 2 29 -
trunk/Source/WebCore/platform/PlatformStrategies.cpp
r196174 r268904 31 31 static PlatformStrategies* s_platformStrategies; 32 32 33 bool hasPlatformStrategies() 34 { 35 return !!s_platformStrategies; 36 } 37 33 38 PlatformStrategies* platformStrategies() 34 39 { -
trunk/Source/WebCore/platform/PlatformStrategies.h
r257551 r268904 82 82 }; 83 83 84 bool hasPlatformStrategies(); 84 85 WEBCORE_EXPORT PlatformStrategies* platformStrategies(); 85 86 WEBCORE_EXPORT void setPlatformStrategies(PlatformStrategies*); -
trunk/Source/WebCore/platform/network/FormData.cpp
r266330 r268904 317 317 } 318 318 319 bool FormData::containsBlobElement() const 320 { 321 for (auto& element : m_elements) { 322 if (WTF::holds_alternative<FormDataElement::EncodedBlobData>(element.data)) 323 return true; 324 } 325 return false; 326 } 327 319 328 Ref<FormData> FormData::resolveBlobReferences(BlobRegistryImpl* blobRegistryImpl) 320 329 { 321 330 // First check if any blobs needs to be resolved, or we can take the fast path. 322 bool hasBlob = false; 323 for (auto& element : m_elements) { 324 if (WTF::holds_alternative<FormDataElement::EncodedBlobData>(element.data)) { 325 hasBlob = true; 326 break; 327 } 328 } 329 330 if (!hasBlob) 331 if (!containsBlobElement()) 331 332 return *this; 332 333 -
trunk/Source/WebCore/platform/network/FormData.h
r266087 r268904 222 222 // If the FormData has no blob references to resolve, this is returned. 223 223 WEBCORE_EXPORT Ref<FormData> resolveBlobReferences(BlobRegistryImpl* = nullptr); 224 bool containsBlobElement() const; 224 225 225 226 WEBCORE_EXPORT FormDataForUpload prepareForUpload(); -
trunk/Source/WebCore/platform/network/cf/FormDataStreamCFNet.cpp
r254089 r268904 32 32 #include "BlobRegistryImpl.h" 33 33 #include "FormData.h" 34 #include "PlatformStrategies.h" 34 35 #include <sys/stat.h> 35 36 #include <sys/types.h> … … 371 372 RetainPtr<CFReadStreamRef> createHTTPBodyCFReadStream(FormData& formData) 372 373 { 374 if (!hasPlatformStrategies() && formData.containsBlobElement()) 375 return nullptr; 376 373 377 auto resolvedFormData = formData.resolveBlobReferences(); 374 378 auto dataForUpload = resolvedFormData->prepareForUpload(); -
trunk/Tools/ChangeLog
r268896 r268904 1 2020-10-22 Alex Christensen <achristensen@webkit.org> 2 3 Null check platformStrategies when making blob read stream for an NSURLRequest 4 https://bugs.webkit.org/show_bug.cgi?id=218112 5 <rdar://problem/70507102> 6 7 Reviewed by Wenson Hsieh. 8 9 * TestWebKitAPI/Tests/WebKitCocoa/NavigationAction.mm: 10 (TEST): 11 1 12 2020-10-22 Jonathan Bedard <jbedard@apple.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/NavigationAction.mm
r260366 r268904 26 26 #import "config.h" 27 27 28 #import "HTTPServer.h" 28 29 #import "PlatformUtilities.h" 29 30 #import "Test.h" 31 #import "TestNavigationDelegate.h" 30 32 #import "TestWKWebView.h" 31 33 #import <WebKit/WKNavigationActionPrivate.h> … … 176 178 EXPECT_FALSE(navigationDelegate.get().navigationAction._shouldPerformDownload); 177 179 } 180 181 TEST(WKNavigationAction, BlobRequestBody) 182 { 183 NSString *html = @"" 184 "<script>" 185 "function bodyLoaded() {" 186 "const form = Object.assign(document.createElement('form'), {" 187 "action: '/formAction', method: 'POST', enctype: 'multipart/form-data'," 188 "});" 189 "document.body.append(form);" 190 "const fileInput = Object.assign(document.createElement('input'), {" 191 "type: 'file', name: 'file'," 192 "});" 193 "form.append(fileInput);" 194 "const dataTransfer = new DataTransfer;" 195 "dataTransfer.items.add(new File(['a'], 'filename'));" 196 "fileInput.files = dataTransfer.files;" 197 "form.submit();" 198 "}" 199 "</script>" 200 "<body onload='bodyLoaded()'>"; 201 auto delegate = [[TestNavigationDelegate new] autorelease]; 202 auto webView = [[WKWebView new] autorelease]; 203 webView.navigationDelegate = delegate; 204 __block bool done = false; 205 delegate.decidePolicyForNavigationAction = ^(WKNavigationAction *action, void (^completionHandler)(WKNavigationActionPolicy)) { 206 EXPECT_NULL(action.request.HTTPBody); 207 if ([action.request.URL.absoluteString isEqualToString:@"about:blank"]) 208 completionHandler(WKNavigationActionPolicyAllow); 209 else { 210 EXPECT_WK_STREQ(action.request.URL.absoluteString, "/formAction"); 211 completionHandler(WKNavigationActionPolicyCancel); 212 done = true; 213 } 214 }; 215 [webView loadHTMLString:html baseURL:nil]; 216 TestWebKitAPI::Util::run(&done); 217 }
Note:
See TracChangeset
for help on using the changeset viewer.