<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>252435</bug_id>
          
          <creation_ts>2023-02-16 15:02:35 -0800</creation_ts>
          <short_desc>[GTK] gdk_memory_texture_new: assertion &apos;width &gt; 0&apos; failed in cairoSurfaceToGdkTexture</short_desc>
          <delta_ts>2024-02-01 07:45:44 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKitGTK</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=258918</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Catanzaro">mcatanzaro</reporter>
          <assigned_to name="Michael Catanzaro">mcatanzaro</assigned_to>
          <cc>bugs-noreply</cc>
    
    <cc>mcatanzaro</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1934335</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2023-02-16 15:02:35 -0800</bug_when>
    <thetext>Reproducer: visit https://dor.mo.gov/forms/?formName=&amp;category=&amp;year=99 and wait until the page loads. It will hit a critical:

#0  _g_log_abort (breakpoint=1) at ../../../../Projects/glib/glib/gmessages.c:558
#1  0x00007f6466d6d739 in g_logv (log_domain=0x7f6466735efb &quot;Gdk&quot;, log_level=G_LOG_LEVEL_CRITICAL, 
    format=0x7f6466dec60f &quot;%s: assertion &apos;%s&apos; failed&quot;, args=0x7ffd73989de8)
    at ../../../../Projects/glib/glib/gmessages.c:1418
#2  0x00007f6466d6d830 in g_log (log_domain=0x7f6466735efb &quot;Gdk&quot;, log_level=G_LOG_LEVEL_CRITICAL, 
    format=0x7f6466dec60f &quot;%s: assertion &apos;%s&apos; failed&quot;) at ../../../../Projects/glib/glib/gmessages.c:1460
#3  0x00007f6466d7088d in g_return_if_fail_warning (log_domain=0x7f6466735efb &quot;Gdk&quot;, 
    pretty_function=0x7f6466736080 &lt;__func__.2&gt; &quot;gdk_memory_texture_new&quot;, expression=0x7f6466735ef1 &quot;width &gt; 0&quot;)
    at ../../../../Projects/glib/glib/gmessages.c:2930
#4  0x00007f64665a3cce in gdk_memory_texture_new (width=0, height=0, format=GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, 
    bytes=0x110c6e0, stride=0) at ../../../../Projects/gtk/gdk/gdkmemorytexture.c:150
#5  0x00007f6463ae646a in WebCore::cairoSurfaceToGdkTexture (
    surface=surface@entry=0x7f6465c6dbe0 &lt;_cairo_surface_nil_invalid_size.lto_priv.0&gt;)
    at /home/mcatanzaro/Projects/WebKit/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp:56
#6  0x00007f64622c5e86 in webkit_web_view_get_snapshot_finish (webView=&lt;optimized out&gt;, result=0x1a38400, 
    error=0x7ffd73989fd0) at /home/mcatanzaro/Projects/WebKit/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp:4897
#7  0x00007f6466f050f6 in on_snapshot_ready (web_view=0x74e6e0, result=0x1a38400, task=0x1b2b480)
    at ../../../../Projects/epiphany/lib/ephy-snapshot-service.c:425
#8  0x00007f6466add58a in g_task_return_now (task=0x1a38400) at ../../../../Projects/glib/gio/gtask.c:1309
#9  0x00007f6466add6d6 in g_task_return (task=0x1a38400, type=G_TASK_RETURN_SUCCESS)
    at ../../../../Projects/glib/gio/gtask.c:1378
#10 0x00007f6466ade2df in g_task_return_pointer (task=0x1a38400, 
    result=0x7f6465c6dbe0 &lt;_cairo_surface_nil_invalid_size.lto_priv.0&gt;, 
    result_destroy=0x7f6465bf07a0 &lt;INT_cairo_surface_destroy&gt;) at ../../../../Projects/glib/gio/gtask.c:1812
#11 0x00007f64622c943d in webkit_web_view_get_snapshot::$_9::operator() (handle=..., this=&lt;optimized out&gt;)
    at /home/mcatanzaro/Projects/WebKit/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp:4867
#12 WTF::Detail::CallableWrapper&lt;webkit_web_view_get_snapshot::$_9, void, WebKit::ShareableBitmapHandle const&amp;&gt;::call
    (this=0x7f645200c0f0, in=...) at WTF/Headers/wtf/Function.h:53
#13 0x00007f646222dbe7 in WTF::Function&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;::operator()(WebKit::ShareableBitmapHandle const&amp;) const (in=..., this=&lt;optimized out&gt;) at WTF/Headers/wtf/Function.h:82
#14 WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;::operator()(WebKit::ShareableBitmapHandle const&amp;) (this=0x7f645200c328, in=...) at WTF/Headers/wtf/CompletionHandler.h:75
#15 std::__invoke_impl&lt;void, WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;, WebKit::ShareableBitmapHandle&gt;(std::__invoke_other, WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;&amp;&amp;, WebKit::ShareableBitmapHandle&amp;&amp;) (__f=..., __args=...)
    at /usr/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/invoke.h:61
#16 std::__invoke&lt;WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;, WebKit::ShareableBitmapHandle&gt;(WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;&amp;&amp;, WebKit::ShareableBitmapHandle&amp;&amp;) (__fn=..., 
    __args=...) at /usr/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/invoke.h:96
#17 std::__apply_impl&lt;WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;, std::tuple&lt;WebKit::ShareableBitmapHandle&gt;, 0ul&gt;(WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;&amp;&amp;, std::tuple&lt;WebKit::ShareableBitmapHandle&gt;&amp;&amp;, std::integer_sequence&lt;unsigned long, 0ul&gt;) (__f=..., __t=...)
    at /usr/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/tuple:1852
#18 std::apply&lt;WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;, std::tuple&lt;WebKit::ShareableBitmapHandle&gt; &gt;(WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;&amp;&amp;, std::tuple&lt;WebKit::ShareableBitmapHandle&gt;&amp;&amp;) (__f=..., __t=...) at /usr/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/tuple:1863
#19 IPC::Connection::callReply&lt;Messages::WebPage::TakeSnapshot, WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt; &gt;(IPC::Decoder&amp;, WTF::CompletionHandler&lt;void (WebKit::ShareableBitmapHandle const&amp;)&gt;&amp;&amp;) (decoder=..., 
    completionHandler=...) at /home/mcatanzaro/Projects/WebKit/Source/WebKit/Platform/IPC/Connection.h:704
#20 0x00007f64621a3c26 in WTF::Function&lt;void (IPC::Decoder*)&gt;::operator()(IPC::Decoder*) const (in=0x0, 
    this=&lt;optimized out&gt;) at WTF/Headers/wtf/Function.h:82
#21 WTF::CompletionHandler&lt;void (IPC::Decoder*)&gt;::operator()(IPC::Decoder*) (this=&lt;optimized out&gt;, in=0x0)
--Type &lt;RET&gt; for more, q to quit, c to continue without paging--c
    at WTF/Headers/wtf/CompletionHandler.h:75
#22 WebKit::AuxiliaryProcessProxy::sendMessage(WTF::UniqueRef&lt;IPC::Encoder&gt;&amp;&amp;, WTF::OptionSet&lt;IPC::SendOption&gt;, std::optional&lt;IPC::Connection::AsyncReplyHandler&gt;, WebKit::AuxiliaryProcessProxy::ShouldStartProcessThrottlerActivity)::$_1::operator()(IPC::Decoder*) (this=&lt;optimized out&gt;, decoder=0x0) at /home/mcatanzaro/Projects/WebKit/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:219
#23 WTF::Detail::CallableWrapper&lt;WebKit::AuxiliaryProcessProxy::sendMessage(WTF::UniqueRef&lt;IPC::Encoder&gt;&amp;&amp;, WTF::OptionSet&lt;IPC::SendOption&gt;, std::optional&lt;IPC::Connection::AsyncReplyHandler&gt;, WebKit::AuxiliaryProcessProxy::ShouldStartProcessThrottlerActivity)::$_1, void, IPC::Decoder*&gt;::call(IPC::Decoder*) (this=&lt;optimized out&gt;, in=0x0) at WTF/Headers/wtf/Function.h:53
#24 0x00007f6462142485 in WTF::Function&lt;void (IPC::Decoder*)&gt;::operator()(IPC::Decoder*) const (in=0x7f6452118270, this=&lt;optimized out&gt;) at WTF/Headers/wtf/Function.h:82
#25 WTF::CompletionHandler&lt;void (IPC::Decoder*)&gt;::operator()(IPC::Decoder*) (this=0x7ffd7398a178, in=0x7f6452118270) at WTF/Headers/wtf/CompletionHandler.h:75
#26 IPC::Connection::dispatchMessage (this=0x7f645215c1a0, decoder=...) at /home/mcatanzaro/Projects/WebKit/Source/WebKit/Platform/IPC/Connection.cpp:1179
#27 0x00007f6462142606 in IPC::Connection::dispatchMessage (this=0x7f645215c1a0, message=std::unique_ptr&lt;IPC::Decoder&gt; = {...}) at /home/mcatanzaro/Projects/WebKit/Source/WebKit/Platform/IPC/Connection.cpp:1245
#28 0x00007f6462142b82 in IPC::Connection::dispatchIncomingMessages (this=0x7f645215c1a0) at /home/mcatanzaro/Projects/WebKit/Source/WebKit/Platform/IPC/Connection.cpp:1355
#29 0x00007f6460eba31c in WTF::Function&lt;void ()&gt;::operator()() const (this=&lt;optimized out&gt;) at /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/Function.h:82
#30 WTF::RunLoop::performWork (this=0x7f64520100e0) at /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/RunLoop.cpp:147
#31 0x00007f6460f1b8c6 in WTF::RunLoop::RunLoop()::$_1::operator()(void*) const (userData=0x1, userData@entry=0x7f64520100e0, this=&lt;optimized out&gt;) at /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/glib/RunLoopGLib.cpp:80
#32 WTF::RunLoop::RunLoop()::$_1::__invoke(void*) (userData=0x1, userData@entry=0x7f64520100e0) at /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/glib/RunLoopGLib.cpp:79
#33 0x00007f6460f1adfa in WTF::RunLoop::$_0::operator() (source=0x7717c0, callback=0x7f6460f1b8c0 &lt;WTF::RunLoop::RunLoop()::$_1::__invoke(void*)&gt;, userData=0x7f64520100e0, this=&lt;optimized out&gt;) at /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/glib/RunLoopGLib.cpp:53
#34 WTF::RunLoop::$_0::__invoke (source=0x7717c0, callback=0x7f6460f1b8c0 &lt;WTF::RunLoop::RunLoop()::$_1::__invoke(void*)&gt;, userData=0x7f64520100e0) at /home/mcatanzaro/Projects/WebKit/Source/WTF/wtf/glib/RunLoopGLib.cpp:45
#35 0x00007f6466d6071b in g_main_dispatch (context=0x732a90) at ../../../../Projects/glib/glib/gmain.c:3460
#36 0x00007f6466d6168f in g_main_context_dispatch (context=0x732a90) at ../../../../Projects/glib/glib/gmain.c:4200
#37 0x00007f6466d61882 in g_main_context_iterate (context=0x732a90, block=1, dispatch=1, self=0x738950) at ../../../../Projects/glib/glib/gmain.c:4276
#38 0x00007f6466d61946 in g_main_context_iteration (context=0x732a90, may_block=1) at ../../../../Projects/glib/glib/gmain.c:4343
#39 0x00007f6466b1edc2 in g_application_run (application=0x777240, argc=1, argv=0x7ffd7398a668) at ../../../../Projects/glib/gio/gapplication.c:2573
#40 0x0000000000404d48 in main (argc=1, argv=0x7ffd7398a668) at ../../../../Projects/epiphany/src/ephy-main.c:434</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1934348</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2023-02-16 15:15:48 -0800</bug_when>
    <thetext>So an initial fix is:

diff --git a/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp b/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp
index 299bea86401d..43c20263e429 100644
--- a/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp
+++ b/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp
@@ -48,6 +48,8 @@ GRefPtr&lt;GdkTexture&gt; cairoSurfaceToGdkTexture(cairo_surface_t* surface)
     ASSERT(cairo_image_surface_get_format(surface) == CAIRO_FORMAT_ARGB32);
     auto width = cairo_image_surface_get_width(surface);
     auto height = cairo_image_surface_get_height(surface);
+    if (width &lt;= 0 || height &lt;= 0)
+        return nullptr;
     auto stride = cairo_image_surface_get_stride(surface);
     auto* data = cairo_image_surface_get_data(surface);
     GRefPtr&lt;GBytes&gt; bytes = adoptGRef(g_bytes_new_with_free_func(data, height * stride, [](gpointer data) {

But then Epiphany crashes later on in ephy_snapshot_service_prepare_snapshot() in basically the same way, and it doesn&apos;t look like Epiphany, fault. Problem is webkit_web_view_get_snapshot_finish() can return nullptr without setting the error parameter. I think we should set WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE error when returning nullptr, does that sound OK?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1934765</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2023-02-17 16:17:32 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/10310</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2009735</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-02-01 07:45:41 -0800</bug_when>
    <thetext>Committed 273907@main (39559cbd2d25): &lt;https://commits.webkit.org/273907@main&gt;

Reviewed commits have been landed. Closing PR #10310 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>