aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsimportvisitor.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-09-24 13:49:42 +0200
committerUlf Hermann <ulf.hermann@qt.io>2024-09-25 21:24:12 +0200
commitdea8e38d95508acd67da997d0c2a9c91ef1bc887 (patch)
treeda873c76e6037ecd061bd7d7724966b8ccf58032 /src/qmlcompiler/qqmljsimportvisitor.cpp
parent724c48f60a5ffdcd95f99863e215185d05f47a59 (diff)
QmlCompiler: Do not miscompile ID lookups in invalid types
If we cannot resolve a type, we need to assume that all its properties are components and assign separate contexts to all inner objects. Otherwise, if one of them actually is, the attempt to resolve it at run time will crash. Pick-to: 6.8 Fixes: QTBUG-129281 Change-Id: Ic34b5308accdd93f6797ee39fcd56040cf86b1ce Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsimportvisitor.cpp')
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index 26b5348f21..7186adb88c 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -610,6 +610,12 @@ void QQmlJSImportVisitor::processDefaultProperties()
const QQmlJSMetaProperty defaultProp = parentScope->property(defaultPropertyName);
auto propType = defaultProp.type();
const auto handleUnresolvedDefaultProperty = [&](const QQmlJSScope::ConstPtr &) {
+
+ // Since we don't know the property type, we need to assume it's QQmlComponent and that
+ // IDs from the inner scopes are inaccessible.
+ for (const QQmlJSScope::Ptr &scope : std::as_const(*it))
+ scope->setIsWrappedInImplicitComponent(true);
+
// Property type is not fully resolved we cannot tell any more than this
m_logger->log(QStringLiteral("Property \"%1\" has incomplete type \"%2\". You may be "
"missing an import.")
@@ -735,9 +741,20 @@ void QQmlJSImportVisitor::processPropertyBindingObjects()
for (const PendingPropertyObjectBinding &objectBinding :
std::as_const(m_pendingPropertyObjectBindings)) {
const QString propertyName = objectBinding.name;
- QQmlJSScope::ConstPtr childScope = objectBinding.childScope;
+ QQmlJSScope::Ptr childScope = objectBinding.childScope;
- if (!isTypeResolved(objectBinding.scope)) // guarantees property lookup
+ const auto handleUnresolvedType = [&](const QQmlJSScope::ConstPtr &type) {
+ // Since we don't know the property type we need to assume that it's QQmlComponent and
+ // that IDs from the child scope are inaccessible outside of it.
+ childScope->setIsWrappedInImplicitComponent(true);
+
+ m_logger->log(QStringLiteral("Type %1 is used but it is not resolved")
+ .arg(getScopeName(type, type->scopeType())),
+ qmlUnresolvedType, type->sourceLocation());
+ };
+
+ // guarantees property lookup
+ if (!isTypeResolved(objectBinding.scope, handleUnresolvedType))
continue;
QQmlJSMetaProperty property = objectBinding.scope->property(propertyName);
@@ -748,6 +765,11 @@ void QQmlJSImportVisitor::processPropertyBindingObjects()
continue;
}
const auto handleUnresolvedProperty = [&](const QQmlJSScope::ConstPtr &) {
+
+ // Since we don't know the property type we need to assume that it's QQmlComponent and
+ // that IDs from the child scope are inaccessible outside of it.
+ childScope->setIsWrappedInImplicitComponent(true);
+
// Property type is not fully resolved we cannot tell any more than this
m_logger->log(QStringLiteral("Property \"%1\" has incomplete type \"%2\". You may be "
"missing an import.")
@@ -774,7 +796,7 @@ void QQmlJSImportVisitor::processPropertyBindingObjects()
continue;
}
- objectBinding.childScope->setIsWrappedInImplicitComponent(
+ childScope->setIsWrappedInImplicitComponent(
causesImplicitComponentWrapping(property, childScope));
// unique because it's per-scope and per-property