Commit 10fb3ead authored by Eike Ziller's avatar Eike Ziller
Browse files

Fix that bogus mime data could lead to endless loop



<mime-type type="text/foo">
  <sub-class-of type="text/foo"/>
</mime-type>

Change-Id: Id03cb4a37345ccc083eaaa03c33847b3735a5d4b
Task-number: QTCREATORBUG-13965
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent b7473459
......@@ -230,13 +230,19 @@ bool MimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
const QString resolvedParent = provider()->resolveAlias(parent);
//Q_ASSERT(provider()->resolveAlias(mime) == mime);
QStack<QString> toCheck;
QSet<QString> seen; // avoid endless loop on bogus mime data
toCheck.push(mime);
seen.insert(mime);
while (!toCheck.isEmpty()) {
const QString current = toCheck.pop();
if (current == resolvedParent)
return true;
foreach (const QString &par, provider()->parents(current))
toCheck.push(par);
foreach (const QString &par, provider()->parents(current)) {
int seenSize = seen.size();
seen.insert(par);
if (seen.size() != seenSize) // haven't seen before, so add
toCheck.push(par);
}
}
return false;
}
......
......@@ -2516,7 +2516,9 @@ static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType,
// * application/octet-stream
// * text/plain
QList<Utils::MimeType> queue;
QSet<QString> seen;
queue.append(mimeType);
seen.insert(mimeType.name());
while (!queue.isEmpty()) {
Utils::MimeType mt = queue.takeFirst();
// check for matching factories
......@@ -2536,8 +2538,14 @@ static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType,
QStringList parentNames = mt.parentMimeTypes();
foreach (const QString &parentName, parentNames) {
const Utils::MimeType parent = mdb.mimeTypeForName(parentName);
if (parent.isValid())
queue.append(parent);
if (parent.isValid()) {
int seenSize = seen.size();
seen.insert(parent.name());
if (seen.size() != seenSize) // not seen before, so add
queue.append(parent);
else
qWarning("MimeTypes: Parent hierarchy loop detected for '%s'!", qPrintable(parent.name()));
}
}
}
}
......
Markdown is supported
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