Title: [182537] trunk
Revision
182537
Author
[email protected]
Date
2015-04-08 08:29:25 -0700 (Wed, 08 Apr 2015)

Log Message

[GTK] Crash in DOMObjectCache when a wrapped object owned by the cache is unreffed by the user
https://bugs.webkit.org/show_bug.cgi?id=143521

Reviewed by Martin Robinson.

This is a case we claim to support, but it only works if the
object has only one reference. In that case, when the user unrefs
it, the weak ref notify callback removes the object from the
cache. However, if the object has more than one ref, the cache
doesn't know the user unreffed it, and when clearing the cache we
try to remove more references than what the object actually has,
causing a crash in g_object_unref.

* bindings/gobject/DOMObjectCache.cpp:
(WebKit::DOMObjectCacheData::clearObject):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (182536 => 182537)


--- trunk/Source/WebCore/ChangeLog	2015-04-08 15:11:56 UTC (rev 182536)
+++ trunk/Source/WebCore/ChangeLog	2015-04-08 15:29:25 UTC (rev 182537)
@@ -1,3 +1,21 @@
+2015-04-08  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Crash in DOMObjectCache when a wrapped object owned by the cache is unreffed by the user
+        https://bugs.webkit.org/show_bug.cgi?id=143521
+
+        Reviewed by Martin Robinson.
+
+        This is a case we claim to support, but it only works if the
+        object has only one reference. In that case, when the user unrefs
+        it, the weak ref notify callback removes the object from the
+        cache. However, if the object has more than one ref, the cache
+        doesn't know the user unreffed it, and when clearing the cache we
+        try to remove more references than what the object actually has,
+        causing a crash in g_object_unref.
+
+        * bindings/gobject/DOMObjectCache.cpp:
+        (WebKit::DOMObjectCacheData::clearObject):
+
 2015-04-08  Zalan Bujtas  <[email protected]>
 
         Simple line layout: Add <br> support.

Modified: trunk/Source/WebCore/bindings/gobject/DOMObjectCache.cpp (182536 => 182537)


--- trunk/Source/WebCore/bindings/gobject/DOMObjectCache.cpp	2015-04-08 15:11:56 UTC (rev 182536)
+++ trunk/Source/WebCore/bindings/gobject/DOMObjectCache.cpp	2015-04-08 15:29:25 UTC (rev 182537)
@@ -43,7 +43,11 @@
     {
         ASSERT(object);
         ASSERT(cacheReferences >= 1);
+        ASSERT(object->ref_count >= 1);
 
+        // Make sure we don't unref more than the references the object actually has. It can happen that user
+        // unreffed a reference owned by the cache.
+        cacheReferences = std::min(static_cast<unsigned>(object->ref_count), cacheReferences);
         GRefPtr<GObject> protect(object);
         do {
             g_object_unref(object);

Modified: trunk/Tools/ChangeLog (182536 => 182537)


--- trunk/Tools/ChangeLog	2015-04-08 15:11:56 UTC (rev 182536)
+++ trunk/Tools/ChangeLog	2015-04-08 15:29:25 UTC (rev 182537)
@@ -1,3 +1,22 @@
+2015-04-08  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Crash in DOMObjectCache when a wrapped object owned by the cache is unreffed by the user
+        https://bugs.webkit.org/show_bug.cgi?id=143521
+
+        Reviewed by Martin Robinson.
+
+        Add a way to detect unexpected web process crashes to WebViewTest,
+        and a test case to testDOMCache to trigger the crash.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp:
+        (WebKitDOMNodeTest::testDOMCache):
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp:
+        (testWebKitWebViewProcessCrashed):
+        * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
+        (WebViewTest::WebViewTest):
+        (WebViewTest::webProcessCrashed):
+        * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h:
+
 2015-04-07  Alexey Proskuryakov  <[email protected]>
 
         PageVisibilityStateWithWindowChanges should only be enabled on Yosemite

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp (182536 => 182537)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp	2015-04-08 15:11:56 UTC (rev 182536)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp	2015-04-08 15:29:25 UTC (rev 182537)
@@ -231,6 +231,12 @@
         g_assert(WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT(p2.get()));
         assertObjectIsDeletedWhenTestFinishes(G_OBJECT(p2.get()));
 
+        // Manually handling a DOM object owned by the cache shouldn't crash when the cache has more than one reference.
+        GRefPtr<WebKitDOMElement> p3 = adoptGRef(webkit_dom_document_create_element(document, "P", nullptr));
+        g_assert(WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT(p3.get()));
+        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(p3.get()));
+        webkit_dom_node_append_child(WEBKIT_DOM_NODE(div), WEBKIT_DOM_NODE(p3.get()), nullptr);
+
         // DOM objects removed from the document are also correctly handled by the cache.
         WebKitDOMElement* a = webkit_dom_document_create_element(document, "A", nullptr);
         g_assert(WEBKIT_DOM_IS_ELEMENT(a));

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp (182536 => 182537)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp	2015-04-08 15:11:56 UTC (rev 182536)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp	2015-04-08 15:29:25 UTC (rev 182537)
@@ -88,9 +88,11 @@
     test->loadHtml("<html></html>", 0);
     test->waitUntilLoadFinished();
 
-    g_signal_connect(test->m_webView, "web-process-crashed",
+    g_signal_connect_after(test->m_webView, "web-process-crashed",
         G_CALLBACK(webProcessCrashedCallback), test);
 
+    test->m_expectedWebProcessCrash = true;
+
     GUniquePtr<char> extensionBusName(g_strdup_printf("org.webkit.gtk.WebExtensionTest%u", Test::s_webExtensionID));
     GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy(extensionBusName.get(),
         "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", test->m_mainLoop));
@@ -103,6 +105,7 @@
         -1, 0, 0));
     g_assert(!result);
     g_main_loop_run(test->m_mainLoop);
+    test->m_expectedWebProcessCrash = false;
 }
 
 static void testWebExtensionWindowObjectCleared(WebViewTest* test, gconstpointer)

Modified: trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp (182536 => 182537)


--- trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp	2015-04-08 15:11:56 UTC (rev 182536)
+++ trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp	2015-04-08 15:29:25 UTC (rev 182537)
@@ -31,8 +31,10 @@
     , m_javascriptResult(nullptr)
     , m_resourceDataSize(0)
     , m_surface(nullptr)
+    , m_expectedWebProcessCrash(false)
 {
     assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView));
+    g_signal_connect(m_webView, "web-process-crashed", G_CALLBACK(WebViewTest::webProcessCrashed), this);
 }
 
 WebViewTest::~WebViewTest()
@@ -47,6 +49,16 @@
     g_main_loop_unref(m_mainLoop);
 }
 
+gboolean WebViewTest::webProcessCrashed(WebKitWebView*, WebViewTest* test)
+{
+    if (test->m_expectedWebProcessCrash) {
+        test->m_expectedWebProcessCrash = false;
+        return FALSE;
+    }
+    g_assert_not_reached();
+    return TRUE;
+}
+
 void WebViewTest::loadURI(const char* uri)
 {
     m_activeURI = uri;

Modified: trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h (182536 => 182537)


--- trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h	2015-04-08 15:11:56 UTC (rev 182536)
+++ trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h	2015-04-08 15:29:25 UTC (rev 182537)
@@ -78,6 +78,8 @@
     // in our constructor, before a derived class's vtable is ready.
     void initializeWebExtensions() override final { Test::initializeWebExtensions(); }
 
+    static gboolean webProcessCrashed(WebKitWebView*, WebViewTest*);
+
     WebKitWebView* m_webView;
     GMainLoop* m_mainLoop;
     CString m_activeURI;
@@ -88,6 +90,7 @@
     GUniquePtr<char> m_resourceData;
     size_t m_resourceDataSize;
     cairo_surface_t* m_surface;
+    bool m_expectedWebProcessCrash;
 
 private:
     void doMouseButtonEvent(GdkEventType, int, int, unsigned, unsigned);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to