Skip to content
Permalink
Browse files

Guard against infinite loop

  • Loading branch information
nyalldawson committed Jun 22, 2018
1 parent 58548e0 commit b2eedd3a5636965154ec07077e1e168c8da21c59
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/core/qgsfileutils.cpp
@@ -17,6 +17,7 @@
#include <QRegularExpression>
#include <QFileInfo>
#include <QDir>
#include <QSet>

QString QgsFileUtils::representFileSize( qint64 bytes )
{
@@ -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() );

0 comments on commit b2eedd3

Please sign in to comment.
You can’t perform that action at this time.