Skip to content

Commit b2eedd3

Browse files
committed
Guard against infinite loop
1 parent 58548e0 commit b2eedd3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/core/qgsfileutils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <QRegularExpression>
1818
#include <QFileInfo>
1919
#include <QDir>
20+
#include <QSet>
2021

2122
QString QgsFileUtils::representFileSize( qint64 bytes )
2223
{
@@ -106,12 +107,17 @@ QString QgsFileUtils::findClosestExistingPath( const QString &path )
106107
else
107108
currentPath = QDir( path );
108109

110+
QSet< QString > visited;
109111
while ( !currentPath.exists() )
110112
{
111113
const QString parentPath = QDir::cleanPath( currentPath.path() + QStringLiteral( "/.." ) );
114+
if ( visited.contains( parentPath ) )
115+
return QString(); // break circular links
116+
112117
if ( parentPath.isEmpty() || parentPath == '.' )
113118
return QString();
114119
currentPath = QDir( parentPath );
120+
visited << parentPath;
115121
}
116122

117123
const QString res = QDir::cleanPath( currentPath.path() );

0 commit comments

Comments
 (0)