fix recursion crash when calling setStyleSheet with qproperty-styleSheet
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Fri, 13 Jan 2023 07:41:54 +0000 (07:41 +0000)
committerDmitry Shachnev <mitya57@debian.org>
Fri, 13 Jan 2023 07:41:54 +0000 (07:41 +0000)
Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=e9cdcc7cb314586a
Last-Update: 2021-11-13

When calling setStyleSheet with property qproperty-styleSheet,
QStyleSheetStyle::polish will call QStyleSheetStyle::setProperties,
and then QStyleSheetStyle::setProperties goes on to call setProperty.
Because there is property qproperty-styleSheet, it will update
stylesheet by calling QStyleSheetStyle::polish.
This causes the recursive call to crash.

Gbp-Pq: Name fix_recursion_crash.diff

src/widgets/styles/qstylesheetstyle.cpp
tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp

index 9fcb8ba5224c47a950d0f467f5c89c871a061f72..da88f0b9717e9a7ffe56d881984b2960776cd337 100644 (file)
@@ -2649,6 +2649,9 @@ void QStyleSheetStyle::setProperties(QWidget *w)
         default: v = decl.d->values.at(0).variant; break;
         }
 
+        if (propertyL1 == QByteArray("styleSheet") && value == v)
+            continue;
+
         w->setProperty(propertyL1, v);
     }
 }
index 26868a763c7ccad8807452effa6f9c5488305d76..5d67ce5acdf52e002a2899de0a54eef753c05afe 100644 (file)
@@ -94,6 +94,7 @@ private slots:
     void layoutSpacing();
 #endif
     void qproperty();
+    void qproperty_styleSheet();
     void palettePropagation_data();
     void palettePropagation();
     void fontPropagation_data();
@@ -678,6 +679,23 @@ void tst_QStyleSheetStyle::qproperty()
     QCOMPARE(pb.isChecked(), false);
 }
 
+void tst_QStyleSheetStyle::qproperty_styleSheet()
+{
+    QWidget w;
+    auto checkBox = new QCheckBox("check", &w);
+    QString sheet = R"(QCheckBox { qproperty-styleSheet: "QCheckBox { qproperty-text: foobar; }"; })";
+
+    QVERIFY(w.property("styleSheet").toString().isEmpty());
+
+    w.setStyleSheet(sheet);
+    QCOMPARE(checkBox->text(), "check");
+
+    //recursion crash
+    w.ensurePolished();
+    QCOMPARE(w.property("styleSheet").toString(), sheet);
+    QCOMPARE(checkBox->text(), "foobar");
+}
+
 namespace ns {
     class PushButton1 : public QPushButton {
         Q_OBJECT