From c0f4442ae0d83e63fc90f1d5058081355f83b701 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 14 Jul 2020 10:19:16 +0200 Subject: Restrict qmlRegisterTypesAndRevisions to major version given We should not register any revisions larger than the given major version as that allows importing an incomplete module, as the version-less import. Typically the offending version is pulled in via some QML_FOREIGN and only the types derived from that foreign class are available in the higher major version. Change-Id: I186fb010d704bea514cefff9f66eb58186df5c91 Reviewed-by: Fabian Kosmale --- .../qml/qmltyperegistrar/tst_qmltyperegistrar.cpp | 7 ++++++ .../qml/qmltyperegistrar/tst_qmltyperegistrar.h | 27 ++++++++++++++++++++++ .../qml/qqmlpropertycache/data/highVersion.qml | 4 ++++ .../qqmlpropertycache/tst_qqmlpropertycache.cpp | 26 +++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 tests/auto/qml/qqmlpropertycache/data/highVersion.qml (limited to 'tests') diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp index 5b468e7b9f..daaa00654e 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp @@ -92,4 +92,11 @@ void tst_qmltyperegistrar::isQProperty() QVERIFY(qmltypesData.contains("Property { name: \"someProperty\"; isQProperty: true; type: \"int\" }")); } +void tst_qmltyperegistrar::restrictToImportVersion() +{ + QVERIFY(qmltypesData.contains("ExcessiveVersion")); + QVERIFY(!qmltypesData.contains("1536")); // Q_REVISION(6, 0) + QVERIFY(!qmltypesData.contains("paletteChanged")); // Added in version 6.0 +} + QTEST_MAIN(tst_qmltyperegistrar) diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h index 840a22658c..c85ae0dae8 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h @@ -34,6 +34,32 @@ #include #include +class ExcessiveVersion : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(int palette READ palette WRITE setPalette NOTIFY paletteChanged REVISION(6, 0)) + +public: + int palette() const { return m_palette; } + + + void setPalette(int palette) + { + if (m_palette == palette) + return; + + m_palette = palette; + emit paletteChanged(); + } + +signals: + Q_REVISION(6, 0) void paletteChanged(); + +private: + int m_palette = 0; +}; + class SizeEnums { Q_GADGET @@ -94,6 +120,7 @@ private slots: void superAndForeignTypes(); void accessSemantics(); void isQProperty(); + void restrictToImportVersion(); private: QByteArray qmltypesData; diff --git a/tests/auto/qml/qqmlpropertycache/data/highVersion.qml b/tests/auto/qml/qqmlpropertycache/data/highVersion.qml new file mode 100644 index 0000000000..9e52cd725c --- /dev/null +++ b/tests/auto/qml/qqmlpropertycache/data/highVersion.qml @@ -0,0 +1,4 @@ +import Test.PropertyCache 4.0 +BaseObject { + highVersion: 200 +} diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp index e885a26057..f00525a37c 100644 --- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp +++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp @@ -57,6 +57,7 @@ private slots: void metaObjectChecksum(); void metaObjectsForRootElements(); void derivedGadgetMethod(); + void restrictRegistrationVersion(); private: QQmlEngine engine; @@ -126,21 +127,38 @@ private: class BaseObject : public QObject { Q_OBJECT + QML_ELEMENT Q_PROPERTY(int propertyA READ propertyA NOTIFY propertyAChanged) Q_PROPERTY(QString propertyB READ propertyB NOTIFY propertyBChanged) + Q_PROPERTY(int highVersion READ highVersion WRITE setHighVersion NOTIFY highVersionChanged REVISION(4, 0)) + public: BaseObject(QObject *parent = nullptr) : QObject(parent) {} int propertyA() const { return 0; } QString propertyB() const { return QString(); } + int highVersion() const { return m_highVersion; } public Q_SLOTS: void slotA() {} + void setHighVersion(int highVersion) + { + if (m_highVersion == highVersion) + return; + + m_highVersion = highVersion; + emit highVersionChanged(); + } + Q_SIGNALS: void propertyAChanged(); void propertyBChanged(); void signalA(); + void highVersionChanged(); + +private: + int m_highVersion = 0; }; class DerivedObject : public BaseObject @@ -648,4 +666,12 @@ void tst_qqmlpropertycache::derivedGadgetMethod() QCOMPARE(gadgetUser->derivedString(), QString::fromLatin1("derived")); } +void tst_qqmlpropertycache::restrictRegistrationVersion() +{ + qmlRegisterTypesAndRevisions("Test.PropertyCache", 3); + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("highVersion.qml")); + QVERIFY(c.isError()); +} + QTEST_MAIN(tst_qqmlpropertycache) -- cgit v1.2.3