Title: [275042] releases/WebKitGTK/webkit-2.32/Source
Revision
275042
Author
[email protected]
Date
2021-03-25 10:06:29 -0700 (Thu, 25 Mar 2021)

Log Message

Merge r274479 - [GTK][WPE] Stop using g_memdup
https://bugs.webkit.org/show_bug.cgi?id=223189

Reviewed by Philippe Normand.

Source/WebCore:

Add gstBufferNewWrappedFast() to create a GstBuffer wrapping data allocated with fast malloc and use it when
possible in combination with fastMemDup() instead of g_memdup().

* platform/graphics/gstreamer/GStreamerCommon.cpp:
(WebCore::gstBufferNewWrappedFast):
* platform/graphics/gstreamer/GStreamerCommon.h:
* platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
(CachedResourceStreamingClient::dataReceived):
* platform/mediastream/gstreamer/RealtimeIncomingAudioSourceLibWebRTC.cpp:
(WebCore::RealtimeIncomingAudioSourceLibWebRTC::OnData):
* platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp:

Source/WebKit:

* UIProcess/API/glib/WebKitWebResource.cpp:
(webkit_web_resource_get_data_finish): Use g_malloc + memcpy instead of g_memdup.
* UIProcess/API/glib/WebKitWebView.cpp:
(webkit_web_view_save_finish): Use fastMemDup instead g_memdup.

Source/WTF:

Add fastMemDup() to replace g_memdup() that is now deprecated in GLib because of the possibility of overflow
when converting from size_t to unsigned int. There's a replacement in GLib already, but we would need to depend
on very new GLib version, so better use fastMemDup() when possible. In cases where we still need to use GLib
allocator, we can simply call g_malloc() + memcpy().

* wtf/FastMalloc.cpp:
(WTF::fastMemDup):
* wtf/FastMalloc.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.32/Source/WTF/ChangeLog (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WTF/ChangeLog	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WTF/ChangeLog	2021-03-25 17:06:29 UTC (rev 275042)
@@ -1,3 +1,19 @@
+2021-03-16  Carlos Garcia Campos  <[email protected]>
+
+        [GTK][WPE] Stop using g_memdup
+        https://bugs.webkit.org/show_bug.cgi?id=223189
+
+        Reviewed by Philippe Normand.
+
+        Add fastMemDup() to replace g_memdup() that is now deprecated in GLib because of the possibility of overflow
+        when converting from size_t to unsigned int. There's a replacement in GLib already, but we would need to depend
+        on very new GLib version, so better use fastMemDup() when possible. In cases where we still need to use GLib
+        allocator, we can simply call g_malloc() + memcpy().
+
+        * wtf/FastMalloc.cpp:
+        (WTF::fastMemDup):
+        * wtf/FastMalloc.h:
+
 2021-03-25  Alberto Garcia  <[email protected]>
 
         REGRESSION(r271560): [Linux] release assert in Thread::initializePlatformThreading

Modified: releases/WebKitGTK/webkit-2.32/Source/WTF/wtf/FastMalloc.cpp (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WTF/wtf/FastMalloc.cpp	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WTF/wtf/FastMalloc.cpp	2021-03-25 17:06:29 UTC (rev 275042)
@@ -97,6 +97,16 @@
     return dup;
 }
 
+void* fastMemDup(const void* mem, size_t bytes)
+{
+    if (!mem || !bytes)
+        return nullptr;
+
+    void* result = fastMalloc(bytes);
+    memcpy(result, mem, bytes);
+    return result;
+}
+
 TryMallocReturnValue tryFastZeroedMalloc(size_t n) 
 {
     void* result;

Modified: releases/WebKitGTK/webkit-2.32/Source/WTF/wtf/FastMalloc.h (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WTF/wtf/FastMalloc.h	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WTF/wtf/FastMalloc.h	2021-03-25 17:06:29 UTC (rev 275042)
@@ -93,6 +93,7 @@
 WTF_EXPORT_PRIVATE void* fastCalloc(size_t numElements, size_t elementSize) RETURNS_NONNULL;
 WTF_EXPORT_PRIVATE void* fastRealloc(void*, size_t) RETURNS_NONNULL;
 WTF_EXPORT_PRIVATE char* fastStrDup(const char*) RETURNS_NONNULL;
+WTF_EXPORT_PRIVATE void* fastMemDup(const void*, size_t);
 
 WTF_EXPORT_PRIVATE TryMallocReturnValue tryFastMalloc(size_t);
 WTF_EXPORT_PRIVATE TryMallocReturnValue tryFastZeroedMalloc(size_t);
@@ -308,6 +309,7 @@
 using WTF::fastMalloc;
 using WTF::fastMallocGoodSize;
 using WTF::fastMallocSize;
+using WTF::fastMemDup;
 using WTF::fastRealloc;
 using WTF::fastStrDup;
 using WTF::fastZeroedMalloc;

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog	2021-03-25 17:06:29 UTC (rev 275042)
@@ -1,3 +1,22 @@
+2021-03-16  Carlos Garcia Campos  <[email protected]>
+
+        [GTK][WPE] Stop using g_memdup
+        https://bugs.webkit.org/show_bug.cgi?id=223189
+
+        Reviewed by Philippe Normand.
+
+        Add gstBufferNewWrappedFast() to create a GstBuffer wrapping data allocated with fast malloc and use it when
+        possible in combination with fastMemDup() instead of g_memdup().
+
+        * platform/graphics/gstreamer/GStreamerCommon.cpp:
+        (WebCore::gstBufferNewWrappedFast):
+        * platform/graphics/gstreamer/GStreamerCommon.h:
+        * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
+        (CachedResourceStreamingClient::dataReceived):
+        * platform/mediastream/gstreamer/RealtimeIncomingAudioSourceLibWebRTC.cpp:
+        (WebCore::RealtimeIncomingAudioSourceLibWebRTC::OnData):
+        * platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp:
+
 2021-03-12  Carlos Garcia Campos  <[email protected]>
 
         [GTK] GTK4 crashes with XVFB: GLXBadWindow

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp	2021-03-25 17:06:29 UTC (rev 275042)
@@ -503,6 +503,11 @@
     return true;
 }
 
+GstBuffer* gstBufferNewWrappedFast(void* data, size_t length)
+{
+    return gst_buffer_new_wrapped_full(static_cast<GstMemoryFlags>(0), data, length, 0, length, data, fastFree);
 }
 
+}
+
 #endif // USE(GSTREAMER)

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h	2021-03-25 17:06:29 UTC (rev 275042)
@@ -300,6 +300,8 @@
     return true;
 });
 
+GstBuffer* gstBufferNewWrappedFast(void* data, size_t length);
+
 }
 
 #ifndef GST_BUFFER_DTS_OR_PTS

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp	2021-03-25 17:06:29 UTC (rev 275042)
@@ -1123,7 +1123,7 @@
 
     checkUpdateBlocksize(length);
 
-    GstBuffer* buffer = gst_buffer_new_wrapped(g_memdup(data, length), length);
+    GstBuffer* buffer = gstBufferNewWrappedFast(fastMemDup(data, length), length);
     gst_adapter_push(members->adapter.get(), buffer);
     stopLoaderIfNeeded(src, members);
     members->responseCondition.notifyOne();

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/mediastream/gstreamer/RealtimeIncomingAudioSourceLibWebRTC.cpp (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/mediastream/gstreamer/RealtimeIncomingAudioSourceLibWebRTC.cpp	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/mediastream/gstreamer/RealtimeIncomingAudioSourceLibWebRTC.cpp	2021-03-25 17:06:29 UTC (rev 275042)
@@ -65,13 +65,13 @@
     gst_audio_info_set_format(&info, format, sampleRate, numberOfChannels, NULL);
 
     auto bufferSize = GST_AUDIO_INFO_BPF(&info) * numberOfFrames;
-    gpointer bufferData = g_malloc(bufferSize);
+    gpointer bufferData = fastMalloc(bufferSize);
     if (muted())
         gst_audio_format_fill_silence(info.finfo, bufferData, bufferSize);
     else
         memcpy(bufferData, audioData, bufferSize);
 
-    auto buffer = adoptGRef(gst_buffer_new_wrapped(bufferData, bufferSize));
+    auto buffer = adoptGRef(gstBufferNewWrappedFast(bufferData, bufferSize));
     auto caps = adoptGRef(gst_audio_info_to_caps(&info));
     auto sample = adoptGRef(gst_sample_new(buffer.get(), caps.get(), nullptr, nullptr));
     GStreamerAudioData data(WTFMove(sample), info);

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp	2021-03-25 17:06:29 UTC (rev 275042)
@@ -221,7 +221,7 @@
         }
 
         // FIXME- Use a GstBufferPool.
-        auto buffer = adoptGRef(gst_buffer_new_wrapped(g_memdup(inputImage.data(), inputImage.size()),
+        auto buffer = adoptGRef(gstBufferNewWrappedFast(fastMemDup(inputImage.data(), inputImage.size()),
             inputImage.size()));
         GST_BUFFER_DTS(buffer.get()) = (static_cast<guint64>(inputImage.Timestamp()) * GST_MSECOND) - m_firstBufferDts;
         GST_BUFFER_PTS(buffer.get()) = (static_cast<guint64>(renderTimeMs) * GST_MSECOND) - m_firstBufferPts;

Modified: releases/WebKitGTK/webkit-2.32/Source/WebKit/ChangeLog (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WebKit/ChangeLog	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WebKit/ChangeLog	2021-03-25 17:06:29 UTC (rev 275042)
@@ -1,3 +1,15 @@
+2021-03-16  Carlos Garcia Campos  <[email protected]>
+
+        [GTK][WPE] Stop using g_memdup
+        https://bugs.webkit.org/show_bug.cgi?id=223189
+
+        Reviewed by Philippe Normand.
+
+        * UIProcess/API/glib/WebKitWebResource.cpp:
+        (webkit_web_resource_get_data_finish): Use g_malloc + memcpy instead of g_memdup.
+        * UIProcess/API/glib/WebKitWebView.cpp:
+        (webkit_web_view_save_finish): Use fastMemDup instead g_memdup.
+
 2021-03-12  Carlos Garcia Campos  <[email protected]>
 
         [GTK] GTK4 crashes with XVFB: GLXBadWindow

Modified: releases/WebKitGTK/webkit-2.32/Source/WebKit/UIProcess/API/glib/WebKitWebResource.cpp (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WebKit/UIProcess/API/glib/WebKitWebResource.cpp	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WebKit/UIProcess/API/glib/WebKitWebResource.cpp	2021-03-25 17:06:29 UTC (rev 275042)
@@ -401,15 +401,22 @@
  */
 guchar* webkit_web_resource_get_data_finish(WebKitWebResource* resource, GAsyncResult* result, gsize* length, GError** error)
 {
-    g_return_val_if_fail(WEBKIT_IS_WEB_RESOURCE(resource), 0);
-    g_return_val_if_fail(g_task_is_valid(result, resource), 0);
+    g_return_val_if_fail(WEBKIT_IS_WEB_RESOURCE(resource), nullptr);
+    g_return_val_if_fail(g_task_is_valid(result, resource), nullptr);
 
     GTask* task = G_TASK(result);
     if (!g_task_propagate_boolean(task, error))
-        return 0;
+        return nullptr;
 
     ResourceGetDataAsyncData* data = ""
     if (length)
         *length = data->webData->size();
-    return static_cast<guchar*>(g_memdup(data->webData->bytes(), data->webData->size()));
+
+    auto* bytes = data->webData->bytes();
+    if (!bytes || !data->webData->size())
+        return nullptr;
+
+    auto* returnValue = g_malloc(data->webData->size());
+    memcpy(returnValue, bytes, data->webData->size());
+    return static_cast<guchar*>(returnValue);
 }

Modified: releases/WebKitGTK/webkit-2.32/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp (275041 => 275042)


--- releases/WebKitGTK/webkit-2.32/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2021-03-25 17:06:19 UTC (rev 275041)
+++ releases/WebKitGTK/webkit-2.32/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2021-03-25 17:06:29 UTC (rev 275042)
@@ -4196,7 +4196,7 @@
     ViewSaveAsyncData* data = ""
     gsize length = data->webData->size();
     if (length)
-        g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(dataStream), g_memdup(data->webData->bytes(), length), length, g_free);
+        g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(dataStream), fastMemDup(data->webData->bytes(), length), length, fastFree);
 
     return dataStream;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to