Skip to content

Commit

Permalink
Guard against infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 22, 2018
1 parent 58548e0 commit b2eedd3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/qgsfileutils.cpp
Expand Up @@ -17,6 +17,7 @@
#include <QRegularExpression>
#include <QFileInfo>
#include <QDir>
#include <QSet>

QString QgsFileUtils::representFileSize( qint64 bytes )
{
Expand Down Expand Up @@ -106,12 +107,17 @@ QString QgsFileUtils::findClosestExistingPath( const QString &path )
else
currentPath = QDir( path );

QSet< QString > visited;
while ( !currentPath.exists() )
{
const QString parentPath = QDir::cleanPath( currentPath.path() + QStringLiteral( "/.." ) );
if ( visited.contains( parentPath ) )
return QString(); // break circular links

if ( parentPath.isEmpty() || parentPath == '.' )
return QString();
currentPath = QDir( parentPath );
visited << parentPath;
}

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

0 comments on commit b2eedd3

Please sign in to comment.