Fix UI freeze when downloading favicons with slow DNS

IconDownloader::setUrl resolved the entry's host name with the blocking QHostInfo::fromName on the GUI thread, only to find out whether the host is an IP address. When the DNS servers are slow or unreachable, the whole window stopped responding until the lookup timed out.

Check the host with UrlTools::isIpAddress instead, which parses the literal address without any network access. Also add IPv6 literal cases to the icon downloader tests.

Fixes #13989
This commit is contained in:
Jessy2027 authored and Jonathan White committed 2026-11-17 08:46:04 -05:00
1 parent 387fc781a2
commit cd42236540
2 files changed
+7 -9

No files matched your search

+3 -9
View File
@@ -21,7 +21,6 @@
#include "networking/NetworkManager.h"
#include <QBuffer>
#include <QHostInfo>
#include <QImageReader>
#include <QNetworkReply>
@@ -72,14 +71,9 @@ void IconDownloader::setUrl(const QString& entryUrl)
QString fullyQualifiedDomain = url.host();
// Determine if host portion of URL is an IP address by resolving it and
// searching for a match with the returned address(es).
bool hostIsIp = false;
QList<QHostAddress> hostAddresses = QHostInfo::fromName(fullyQualifiedDomain).addresses();
hostIsIp =
std::any_of(hostAddresses.begin(), hostAddresses.end(), [&fullyQualifiedDomain](const QHostAddress& addr) {
return addr.toString() == fullyQualifiedDomain;
});
// Determine if host portion of URL is an IP address. This must not resolve the
// host name, as a blocking DNS lookup would freeze the UI.
const bool hostIsIp = UrlTools::isIpAddress(fullyQualifiedDomain);
// Determine the second-level domain, if available
QString secondLevelDomain;
+4
View File
@@ -97,6 +97,10 @@ void TestIconDownloader::testIconDownloader_data()
<< QStringList{"https://user:[email protected]/favicon.ico",
"https://user:[email protected]/favicon.ico",
"https://keepassxc.org/favicon.ico"};
QTest::newRow("Raw IPv6 with schema")
<< "https://[2001:db8::1]" << QStringList{"https://[2001:db8::1]/favicon.ico"};
QTest::newRow("Raw IPv6 with schema and port")
<< "https://[2001:db8::1]:8080" << QStringList{"https://[2001:db8::1]:8080/favicon.ico"};
QTest::newRow("Raw IP with username and password")
<< "https://user:[email protected]" << QStringList{"https://user:[email protected]/favicon.ico"};
QTest::newRow("Relative path should be preserved")