Commit 2d2f972b authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Fix loading xcursor themes with invalid Inherits field

Xcursor loading can get stuck in an infinite recursion if index.theme
file indicates that the theme inherits itself.

In order to prevent that, keep track of the loaded so far themes and
avoid loading already loaded themes.

BUG: 457926
parent 245eb822
Pipeline #225729 failed with stage
in 16 minutes and 12 seconds
......@@ -12,7 +12,9 @@
#include <QDir>
#include <QFile>
#include <QSet>
#include <QSharedData>
#include <QStack>
#include <QStandardPaths>
namespace KWin
......@@ -157,22 +159,36 @@ static QStringList searchPaths()
void KXcursorThemePrivate::load(const QString &themeName, int size, qreal devicePixelRatio)
{
const QStringList paths = searchPaths();
QStringList inherits;
for (const QString &path : paths) {
const QDir dir(path + QLatin1Char('/') + themeName);
if (!dir.exists()) {
QStack<QString> stack;
QSet<QString> loaded;
stack.push(themeName);
while (!stack.isEmpty()) {
const QString themeName = stack.pop();
if (loaded.contains(themeName)) {
continue;
}
loadCursors(dir.filePath(QStringLiteral("cursors")), size, devicePixelRatio);
if (inherits.isEmpty()) {
const KConfig config(dir.filePath(QStringLiteral("index.theme")), KConfig::NoGlobals);
inherits << KConfigGroup(&config, "Icon Theme").readEntry("Inherits", QStringList());
QStringList inherits;
for (const QString &path : paths) {
const QDir dir(path + QLatin1Char('/') + themeName);
if (!dir.exists()) {
continue;
}
loadCursors(dir.filePath(QStringLiteral("cursors")), size, devicePixelRatio);
if (inherits.isEmpty()) {
const KConfig config(dir.filePath(QStringLiteral("index.theme")), KConfig::NoGlobals);
inherits << KConfigGroup(&config, "Icon Theme").readEntry("Inherits", QStringList());
}
}
}
for (const QString &inherit : inherits) {
load(inherit, size, devicePixelRatio);
loaded.insert(themeName);
for (auto it = inherits.crbegin(); it != inherits.crend(); ++it) {
stack.push(*it);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment