Skip to content

Commit

Permalink
jsc_fuz/wktr: *flaky* RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!retai…
Browse files Browse the repository at this point in the history
…nedPointer || !m_controlBlock->objectHasBeenDeleted()); in MediaRecorderPrivateWriter::compressedVideoOutputBufferCallback MediaRecorderPrivateWriterCocoa.mm:107

https://bugs.webkit.org/show_bug.cgi?id=257780
rdar://109659987

Reviewed by Eric Carlson.

After the introduction of ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr,
we are now lazily creating our weak pointer on various threads, and this can happen while destroying the object in main thread.
To make sure we do not end up in that situation, we are now closing MediaRecorderPrivateWriter before destroying it.
In closing, we destroy the compressors which are the ones calling the callbacks that can create the weak pointers.

* LayoutTests/fast/mediastream/mediarecorder-close-expected.txt: Added.
* LayoutTests/fast/mediastream/mediarecorder-close.html: Added.
* Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp:
(WebCore::MediaRecorderPrivateAVFImpl::MediaRecorderPrivateAVFImpl):
* Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h:
* Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm:
(WebCore::MediaRecorderPrivateWriter::~MediaRecorderPrivateWriter):
(WebCore::MediaRecorderPrivateWriter::close):
* Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp:
(WebKit::RemoteMediaRecorder::~RemoteMediaRecorder):

Originally-landed-as: 259548.822@safari-7615-branch (3282e8c). rdar://113224891
Canonical link: https://commits.webkit.org/266596@main
  • Loading branch information
youennf authored and JonWBedard committed Aug 4, 2023
1 parent 6d13b16 commit b08d868
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PASS if not crashing
20 changes: 20 additions & 0 deletions LayoutTests/fast/mediastream/mediarecorder-close.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<body>
<div>PASS if not crashing</div>
<script>
if (window.testRunner)
testRunner.dumpAsText();

onload = async () => {
for (let i = 0; i < 25; i++) {
await caches.has('a');
const stream = await navigator.mediaDevices.getUserMedia({video: true});
const mediaRecorder = new MediaRecorder(stream);
location.hash = 'x';
mediaRecorder.start();
}
};
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ MediaRecorderPrivateAVFImpl::MediaRecorderPrivateAVFImpl(Ref<MediaRecorderPrivat

MediaRecorderPrivateAVFImpl::~MediaRecorderPrivateAVFImpl()
{
m_writer->close();
}

void MediaRecorderPrivateAVFImpl::startRecording(StartRecordingCallback&& callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class WEBCORE_EXPORT MediaRecorderPrivateWriter : public ThreadSafeRefCountedAnd
unsigned audioBitRate() const;
unsigned videoBitRate() const;

void close();

private:
MediaRecorderPrivateWriter(bool hasAudio, bool hasVideo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ - (void)close
MediaRecorderPrivateWriter::~MediaRecorderPrivateWriter()
{
ASSERT(isMainThread());
ASSERT(!m_audioCompressor);
ASSERT(!m_videoCompressor);

m_pendingAudioSampleQueue.clear();
m_pendingVideoFrameQueue.clear();
Expand All @@ -147,6 +149,12 @@ - (void)close
completionHandler(nullptr, 0);
}

void MediaRecorderPrivateWriter::close()
{
m_audioCompressor = nullptr;
m_videoCompressor = nullptr;
}

bool MediaRecorderPrivateWriter::initialize(const MediaRecorderPrivateOptions& options)
{
NSError *error = nil;
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ RemoteMediaRecorder::RemoteMediaRecorder(GPUConnectionToWebProcess& gpuConnectio

RemoteMediaRecorder::~RemoteMediaRecorder()
{
m_writer->close();
}

void RemoteMediaRecorder::audioSamplesStorageChanged(ConsumerSharedCARingBuffer::Handle&& handle, const WebCore::CAAudioStreamDescription& description)
Expand Down

0 comments on commit b08d868

Please sign in to comment.