QQuickPixmapCache: Don't dereference nullptr

Consistently check that job->data is not null before derefencing it.

Fixes: QTBUG-80510
Fixes: QTBUG-79937
Change-Id: I894503ddd2254814463073cc12f8365641efc689
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Fabian Kosmale 2019-12-03 16:23:24 +01:00
parent 75c7f093e0
commit 290251541e
3 changed files with 31 additions and 3 deletions

View File

@ -567,9 +567,10 @@ void QQuickPixmapReader::networkRequestDone(QNetworkReply *reply)
QBuffer buff(&all);
buff.open(QIODevice::ReadOnly);
int frameCount;
if (!readImage(reply->url(), &buff, &image, &errorString, &readSize, &frameCount, job->requestSize, job->providerOptions, nullptr, job->data->frame))
int const frame = job->data ? job->data->frame : 0;
if (!readImage(reply->url(), &buff, &image, &errorString, &readSize, &frameCount, job->requestSize, job->providerOptions, nullptr, frame))
error = QQuickPixmapReply::Decoding;
else
else if (job->data)
job->data->frameCount = frameCount;
}
// send completion event to the QQuickPixmapReply
@ -882,7 +883,8 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
return;
} else {
int frameCount;
if (!readImage(url, &f, &image, &errorStr, &readSize, &frameCount, runningJob->requestSize, runningJob->providerOptions, nullptr, runningJob->data->frame)) {
int const frame = runningJob->data ? runningJob->data->frame : 0;
if ( !readImage(url, &f, &image, &errorStr, &readSize, &frameCount, runningJob->requestSize, runningJob->providerOptions, nullptr, frame)) {
errorCode = QQuickPixmapReply::Loading;
if (f.fileName() != localFile)
errorStr += QString::fromLatin1(" (%1)").arg(f.fileName());

View File

@ -0,0 +1,17 @@
import QtQuick 2.12
Item {
visible: true
width: 640
height: 480
Image{
asynchronous: true
anchors.fill: parent
fillMode: Image.Stretch
source: "exists1.png"
cache: false
sourceSize.width: width/2
sourceSize.height: height/2
}
}

View File

@ -30,6 +30,7 @@
#include <QtQuick/private/qquickpixmapcache_p.h>
#include <QtQml/qqmlengine.h>
#include <QtQuick/qquickimageprovider.h>
#include <QtQml/QQmlComponent>
#include <QNetworkReply>
#include "../../shared/util.h"
#include "testhttpserver.h"
@ -62,6 +63,7 @@ private slots:
#endif
void lockingCrash();
void uncached();
void asynchronousNoCache();
#if PIXMAP_DATA_LEAK_TEST
void dataLeak();
#endif
@ -473,6 +475,13 @@ void tst_qquickpixmapcache::uncached()
}
}
void tst_qquickpixmapcache::asynchronousNoCache()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("asynchronousNoCache.qml"));
QScopedPointer<QObject> root {component.create()}; // should not crash
}
#if PIXMAP_DATA_LEAK_TEST
// This test should not be enabled by default as it