[plasma/plasma-workspace] components/containmentlayoutmanager: containmentlayoutmanager: guard against non-finite item geometry
Nate Graham <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit b2b8fc265f38a1304aebff299e71d1131ff02767 by Nate Graham, on behalf of Shouvik Kar.
Committed on 23/07/2026 at 02:16.
Pushed by ngraham into branch 'master'.
containmentlayoutmanager: guard against non-finite item geometry
containmentlayoutmanager: guard against non-finite item geometry
A malformed ItemGeometries entry containing "inf"/NaN was parsed via QString::toDouble() straight into the applet geometry and then applied as an infinite item size. That sends the desktop layout into a CPU-pegged loop, freezing plasmashell and breaking session D-Bus services (kuiserver etc.), which in turn crashes dependent apps.
Reject non-finite values on both sides:
- when parsing the saved layout, skip such entries so an existing corrupt config can no longer wedge the layout (the applet falls back to automatic placement);
- when serializing, skip items whose geometry is non-finite so the layout manager does not write such a value back to the config.
BUG: 522039
###
M +12 -1 components/containmentlayoutmanager/gridlayoutmanager.cpp
M +5 -0 components/containmentlayoutmanager/itemcontainer.cpp
M +2 -0 components/containmentlayoutmanager/itemcontainer.h
https://invent.kde.org/plasma/plasma-workspace/-/commit/b2b8fc265f38a1304aebff299e71d1131ff02767
diff --git a/components/containmentlayoutmanager/gridlayoutmanager.cpp b/components/containmentlayoutmanager/gridlayoutmanager.cpp
index d947f8fc85..0ba4c9757e 100644
--- a/components/containmentlayoutmanager/gridlayoutmanager.cpp
+++ b/components/containmentlayoutmanager/gridlayoutmanager.cpp
@@ -24,6 +24,9 @@ QString GridLayoutManager::serializeLayout() const
for (auto *item : layout()->childItems()) {
auto *itemCont = qobject_cast<ItemContainer *>(item);
if (itemCont && itemCont != layout()->placeHolder()) {
+ if (!ItemContainer::hasValidGeometry(itemCont->x(), itemCont->y(), itemCont->width(), itemCont->height(), itemCont->rotation())) {
+ continue;
+ }
result += itemCont->key() + QLatin1Char(':') + QString::number(itemCont->x()) + QLatin1Char(',') + QString::number(itemCont->y()) + QLatin1Char(',')
+ QString::number(itemCont->width()) + QLatin1Char(',') + QString::number(itemCont->height()) + QLatin1Char(',')
+ QString::number(itemCont->rotation()) + QLatin1Char(';');
@@ -50,7 +53,15 @@ void GridLayoutManager::parseLayout(const QString &savedLayout)
continue;
}
- m_parsedConfig[id] = {itemGeom[0].toDouble(), itemGeom[1].toDouble(), itemGeom[2].toDouble(), itemGeom[3].toDouble(), itemGeom[4].toDouble()};
+ const qreal gx = itemGeom[0].toDouble();
+ const qreal gy = itemGeom[1].toDouble();
+ const qreal gwidth = itemGeom[2].toDouble();
+ const qreal gheight = itemGeom[3].toDouble();
+ const qreal grotation = itemGeom[4].toDouble();
+ if (!ItemContainer::hasValidGeometry(gx, gy, gwidth, gheight, grotation)) {
+ continue;
+ }
+ m_parsedConfig[id] = {gx, gy, gwidth, gheight, grotation};
}
}
diff --git a/components/containmentlayoutmanager/itemcontainer.cpp b/components/containmentlayoutmanager/itemcontainer.cpp
index f949497e18..e23678ef37 100644
--- a/components/containmentlayoutmanager/itemcontainer.cpp
+++ b/components/containmentlayoutmanager/itemcontainer.cpp
@@ -827,4 +827,9 @@ int ItemContainer::contentHeight() const
return height() - m_topPadding - m_bottomPadding;
}
+bool ItemContainer::hasValidGeometry(qreal x, qreal y, qreal width, qreal height, qreal rotation)
+{
+ return std::isfinite(x) && std::isfinite(y) && std::isfinite(width) && std::isfinite(height) && std::isfinite(rotation);
+}
+
#include "moc_itemcontainer.cpp"
diff --git a/components/containmentlayoutmanager/itemcontainer.h b/components/containmentlayoutmanager/itemcontainer.h
index ed93421ea2..2aecb2c72b 100644
--- a/components/containmentlayoutmanager/itemcontainer.h
+++ b/components/containmentlayoutmanager/itemcontainer.h
@@ -74,6 +74,8 @@ public:
ItemContainer(QQuickItem *parent = nullptr);
~ItemContainer();
+ static bool hasValidGeometry(qreal x, qreal y, qreal width, qreal height, qreal rotation);
+
QQmlListProperty<QObject> contentData();
QString key() const;