haikuwebkit/Source/WebCore/editing/gtk
Chris Dumez 359be8b81c SharedBuffer::takeData() is a bit dangerous
https://bugs.webkit.org/show_bug.cgi?id=228161

Reviewed by Darin Adler.

Source/WebCore:

SharedBuffer::takeData() is a bit dangerous since SharedBuffer is RefCounted and several object may be sharing ownership
of the buffer. Having one owner call takeData() in case ownership is shared leads to bugs such as Bug 228096.

To address the issue, I made SharedBuffer::takeData() private and introduced a new SharedBuffer::extractData() member
function which calls takeData() only if the SharedBuffer is not shared (RefCount is 1) and falls back to calling copyData()
otherwise. I also optimized copyData() a bit by iterating over the segments to build the vector, instead of calling the
potentially very slow SharedBuffer::data().

* Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::FetchBodyConsumer::takeAsBlob):
* Modules/mediarecorder/MediaRecorder.cpp:
(WebCore::createDataAvailableEvent):
* editing/WebCorePasteboardFileReader.cpp:
(WebCore::WebCorePasteboardFileReader::readBuffer):
* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::createFragmentForImageAttachment):
(WebCore::WebContentReader::readImage):
* editing/gtk/WebContentReaderGtk.cpp:
(WebCore::WebContentReader::readImage):
* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::updateEnclosingImageWithData):
* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::copyData):
* platform/SharedBuffer.h:
(WebCore::SharedBuffer::extractData):
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::createResponseBlob):

Source/WTF:

Add Vector::uncheckedAppend() overload that takes in a Span.

* wtf/Vector.h:
(WTF::Vector::uncheckedAppend):
(WTF::Malloc>::uncheckedAppend):


Canonical link: https://commits.webkit.org/239926@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280260 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-07-23 22:05:03 +00:00
..
EditorGtk.cpp
WebContentReaderGtk.cpp SharedBuffer::takeData() is a bit dangerous 2021-07-23 22:05:03 +00:00