From d7c1429b5515c38288e3a33992bf2582c243df5a Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 21 Apr 2023 14:07:53 +0200 Subject: Fix crash with sequential QIODevice as media source on Windows The sample in QTBUG-110005 uses a QNetworkReply as source for QMediaPlayer. This is a sequential QIODevice. As such, it doesn't have the concept of size. The sequence leading to the crash is - BeginCreateObjectFromByteStream() is called - MFStream::GetLength() return zero - that's why MFStream::BeginRead() is not called, and m_currentReadResult stays nullptr - QNetworkReply::readyRead() is emitted - MFStream::doRead() is called, because of the latter signal - MFStream::doRead() accesses m_currentReadResult, which is still nullptr (see above), and we witness the crash The desirable sequence is (as one can inspect by playing a video from a qrc:// URL): - BeginCreateObjectFromByteStream() is called - MFStream::GetLength() returns the video stream's size - MFStream::BeginRead() is called and initializes m_currentReadResult - MFStream::BeginRead() posts a custom event to the MFStream object - MFStream::doRead() is called when handling that custom event - MFStream::EndRead() tears down m_currentReadResult There is never a situation where QIODevice::readRead() should trigger a MFStream::doRead(). Calling doRead() outside of the BeginRead()/EndRead() pair cannot work. Therefore, this patch removes the handling of the stream's readyRead() signal. Note that this patch only fixes the crash in favor of an error code that's written to the program's console. Handling sequential QIODevice streams will require some more work. See further comments in the issue. Pick-to: 6.5 6.2 Fixes: QTBUG-110005 Change-Id: I2fc70f873a2e3a257e8e081d83862c53dabb6cac Reviewed-by: Lars Knoll Reviewed-by: Artem Dyomin --- src/plugins/multimedia/windows/mfstream.cpp | 7 ------- src/plugins/multimedia/windows/mfstream_p.h | 3 --- 2 files changed, 10 deletions(-) diff --git a/src/plugins/multimedia/windows/mfstream.cpp b/src/plugins/multimedia/windows/mfstream.cpp index abbf45c9f..fb37ce293 100644 --- a/src/plugins/multimedia/windows/mfstream.cpp +++ b/src/plugins/multimedia/windows/mfstream.cpp @@ -18,7 +18,6 @@ MFStream::MFStream(QIODevice *stream, bool ownStream) //to make sure invocations on stream //are happened in the same thread of stream object this->moveToThread(stream->thread()); - connect(stream, &QIODevice::readyRead, this, &MFStream::handleReadyRead); } MFStream::~MFStream() @@ -252,12 +251,6 @@ void MFStream::doRead() } } - -void MFStream::handleReadyRead() -{ - doRead(); -} - void MFStream::customEvent(QEvent *event) { if (event->type() != QEvent::User) { diff --git a/src/plugins/multimedia/windows/mfstream_p.h b/src/plugins/multimedia/windows/mfstream_p.h index b8868a01e..a5221ed75 100644 --- a/src/plugins/multimedia/windows/mfstream_p.h +++ b/src/plugins/multimedia/windows/mfstream_p.h @@ -114,9 +114,6 @@ private: void doRead(); -private Q_SLOTS: - void handleReadyRead(); - protected: void customEvent(QEvent *event) override; IMFAsyncResult *m_currentReadResult; -- cgit v1.2.1