Title: [275118] trunk/Source/WebCore
Revision
275118
Author
[email protected]
Date
2021-03-26 15:41:39 -0700 (Fri, 26 Mar 2021)

Log Message

Source/WebCore/editing/cocoa/HTMLConverter.mm:1278:44: runtime error: member call on null pointer of type 'WebCore::ArchiveResource'
https://bugs.webkit.org/show_bug.cgi?id=223696

Reviewed by Alex Christensen.

Fix bug found by UBSan.

* editing/cocoa/HTMLConverter.mm:
(HTMLConverter::_addAttachmentForElement):
- Drop duplicate call to dataSource->subresource(url) as it doesn't seem it can return something else
  than null if it returned null the first time around.
- Make sure resource is null-checked before we dereference it to get the MIME type.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (275117 => 275118)


--- trunk/Source/WebCore/ChangeLog	2021-03-26 22:18:07 UTC (rev 275117)
+++ trunk/Source/WebCore/ChangeLog	2021-03-26 22:41:39 UTC (rev 275118)
@@ -1,3 +1,18 @@
+2021-03-26  Chris Dumez  <[email protected]>
+
+        Source/WebCore/editing/cocoa/HTMLConverter.mm:1278:44: runtime error: member call on null pointer of type 'WebCore::ArchiveResource'
+        https://bugs.webkit.org/show_bug.cgi?id=223696
+
+        Reviewed by Alex Christensen.
+
+        Fix bug found by UBSan.
+
+        * editing/cocoa/HTMLConverter.mm:
+        (HTMLConverter::_addAttachmentForElement):
+        - Drop duplicate call to dataSource->subresource(url) as it doesn't seem it can return something else
+          than null if it returned null the first time around.
+        - Make sure resource is null-checked before we dereference it to get the MIME type.
+
 2021-03-26  Wenson Hsieh  <[email protected]>
 
         Allow some image overlay content to render in fully transparent image elements

Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (275117 => 275118)


--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm	2021-03-26 22:18:07 UTC (rev 275117)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm	2021-03-26 22:41:39 UTC (rev 275118)
@@ -1271,16 +1271,13 @@
             fileWrapper = adoptNS([[NSFileWrapper alloc] initWithURL:url options:0 error:NULL]);
     }
     if (!fileWrapper && dataSource) {
-        RefPtr<ArchiveResource> resource = dataSource->subresource(url);
-        if (!resource)
-            resource = dataSource->subresource(url);
-
-        const String& mimeType = resource->mimeType();
-        if (usePlaceholder && resource && mimeType == "text/html")
-            notFound = YES;
-        if (resource && !notFound) {
-            fileWrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:resource->data().createNSData().get()]);
-            [fileWrapper setPreferredFilename:suggestedFilenameWithMIMEType(url, mimeType)];
+        if (auto resource = dataSource->subresource(url)) {
+            auto& mimeType = resource->mimeType();
+            if (!usePlaceholder || mimeType != "text/html") {
+                fileWrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:resource->data().createNSData().get()]);
+                [fileWrapper setPreferredFilename:suggestedFilenameWithMIMEType(url, mimeType)];
+            } else
+                notFound = YES;
         }
     }
 #if !PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to