summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2018-09-21 12:58:20 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2018-09-21 10:19:39 +0000
commit78a2bf804d319359e9d2d975d1918412c8756bfd (patch)
treeda9dc9612977dcefc87f381066f16859dca1e2e4
parent411d877bd1e4068d63f2ecbd448b8c3585c3f25d (diff)
Fix crashes when dealing with malformed qml filesv2.1.0-rc
Attempting to determine the qml file type (script or qml-stream) assumed there was always a valid root object. If the qml file had a bug that caused loading it to fail, that assumption caused a crash. Task-number: QT3DS-2381 Change-Id: I7016540fe48593dff3f01107dc6826f1f6d3929f Reviewed-by: Antti Määttä <antti.maatta@qt.io>
-rw-r--r--src/Authoring/Studio/Application/StudioApp.cpp8
-rw-r--r--src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp29
-rw-r--r--src/Authoring/Studio/Palettes/Project/ProjectView.cpp10
-rw-r--r--src/Authoring/Studio/Utils/ImportUtils.cpp12
4 files changed, 36 insertions, 23 deletions
diff --git a/src/Authoring/Studio/Application/StudioApp.cpp b/src/Authoring/Studio/Application/StudioApp.cpp
index 91b1ab92..a5328c13 100644
--- a/src/Authoring/Studio/Application/StudioApp.cpp
+++ b/src/Authoring/Studio/Application/StudioApp.cpp
@@ -1990,9 +1990,11 @@ QSize CStudioApp::getRenderableSize(const QString &renderableId)
r.m_size = PresentationFile::readSize(path);
} else { // QML stream
QQmlApplicationEngine qmlEngine(path);
- QQuickItem *item = qobject_cast<QQuickItem *>(qmlEngine.rootObjects().at(0));
- if (item)
- r.m_size = QSize(qRound(item->width()), qRound(item->height()));
+ if (qmlEngine.rootObjects().size() > 0) {
+ QQuickItem *item = qobject_cast<QQuickItem *>(qmlEngine.rootObjects().at(0));
+ if (item)
+ r.m_size = QSize(qRound(item->width()), qRound(item->height()));
+ }
}
}
return r.m_size;
diff --git a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp
index 643b6690..1588a745 100644
--- a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp
+++ b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp
@@ -440,19 +440,24 @@ void ProjectFileSystemModel::importUrl(QDir &targetDir, const QUrl &url)
QObject *qmlRoot = nullptr;
if (extension == QLatin1String("qml")) {
qmlEngine.load(sourceFile);
- const char *rootClassName = qmlEngine.rootObjects().at(0)
- ->metaObject()->superClass()->className();
-
- // the assumption here is that any qml that is not a behavior is a qml stream
- if (strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0) { // not a behavior
- qmlRoot = qmlEngine.rootObjects().at(0);
-
- // put the qml in the correct folder
- if (targetDir.path().endsWith(QLatin1String("/scripts"))) {
- const QString path(QStringLiteral("../qml streams"));
- targetDir.mkpath(path); // create the folder if doesn't exist (i.e. old project)
- targetDir.cd(path);
+ if (qmlEngine.rootObjects().size() > 0) {
+ const char *rootClassName = qmlEngine.rootObjects().at(0)
+ ->metaObject()->superClass()->className();
+ // the assumption here is that any qml that is not a behavior is a qml stream
+ if (strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0) { // not a behavior
+ qmlRoot = qmlEngine.rootObjects().at(0);
+ // put the qml in the correct folder
+ if (targetDir.path().endsWith(QLatin1String("/scripts"))) {
+ const QString path(QStringLiteral("../qml streams"));
+ targetDir.mkpath(path); // create the folder if doesn't exist
+ targetDir.cd(path);
+ }
}
+ } else {
+ // Invalid qml file, block import
+ g_StudioApp.GetDialogs()->DisplayKnownErrorDialog(
+ tr("Failed to parse '%1'\nAborting import.").arg(sourceFile));
+ return;
}
}
// Copy the file to target directory
diff --git a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp
index 72964c04..05c68ecd 100644
--- a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp
+++ b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp
@@ -372,9 +372,13 @@ bool ProjectView::isQmlStream(int row) const
return false;
QQmlApplicationEngine qmlEngine(filePath);
- const char *rootClassName = qmlEngine.rootObjects().at(0)
- ->metaObject()->superClass()->className();
- return strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0;
+ if (qmlEngine.rootObjects().size() > 0) {
+ const char *rootClassName = qmlEngine.rootObjects().at(0)
+ ->metaObject()->superClass()->className();
+ return strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0;
+ } else {
+ return false;
+ }
}
bool ProjectView::isRefreshable(int row) const
diff --git a/src/Authoring/Studio/Utils/ImportUtils.cpp b/src/Authoring/Studio/Utils/ImportUtils.cpp
index 46ba9efa..2bb4807c 100644
--- a/src/Authoring/Studio/Utils/ImportUtils.cpp
+++ b/src/Authoring/Studio/Utils/ImportUtils.cpp
@@ -57,11 +57,13 @@ SObjectFileType ImportUtils::GetObjectFileTypeForFile(const CFilePath &inFile,
} else if (theExtension.Compare(CDialogs::GetQmlFileExtension(),
Q3DStudio::CString::ENDOFSTRING, false)) {
QQmlApplicationEngine qmlEngine(inFile.absoluteFilePath());
- const char *rootClassName = qmlEngine.rootObjects().at(0)
- ->metaObject()->superClass()->className();
- bool isQmlStream = strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0;
- return isQmlStream ? SObjectFileType(OBJTYPE_QML_STREAM, DocumentEditorFileType::QmlStream)
- : SObjectFileType(OBJTYPE_BEHAVIOR, DocumentEditorFileType::Behavior);
+ if (qmlEngine.rootObjects().size() > 0) {
+ const char *rootClassName = qmlEngine.rootObjects().at(0)
+ ->metaObject()->superClass()->className();
+ bool isQmlStream = strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0;
+ return isQmlStream ? SObjectFileType(OBJTYPE_QML_STREAM, DocumentEditorFileType::QmlStream)
+ : SObjectFileType(OBJTYPE_BEHAVIOR, DocumentEditorFileType::Behavior);
+ } // If qml file is invalid, it will be of unknown type
} else if (CDialogs::IsFontFileExtension(theExtension)) {
return SObjectFileType(OBJTYPE_TEXT, DocumentEditorFileType::Font);
} else if (CDialogs::IsEffectFileExtension(theExtension)) {