From 094869d4a88c3d0187d2f9c03294ce32f3503533 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Mon, 30 Oct 2017 16:30:50 +0300 Subject: QDirIterator: Skip inconvertible file names on Unix In the case when user's local encoding is UTF-8, QDirIterator may list entries which names can't be correctly converted from UTF-8 to UTF-16, e.g. for "\xC0\xB0" file name QDirIterator::fileName() returns "\uFFFD\uFFFD" (FFFD is a code of Replacement Character). The problem is that you can't do anything with such directory entries because there is no way to get the original entry names. List only those names that can be converted to QString and then back to the local encoding without corruption. Change-Id: Ib6a71dea8ce9601876040c07276c325fd997e767 Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemiterator_unix.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qfilesystemiterator_unix.cpp b/src/corelib/io/qfilesystemiterator_unix.cpp index 0d1438f137..a9acf542d4 100644 --- a/src/corelib/io/qfilesystemiterator_unix.cpp +++ b/src/corelib/io/qfilesystemiterator_unix.cpp @@ -77,12 +77,19 @@ bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaDa if (!dir) return false; - dirEntry = QT_READDIR(dir); + for (;;) { + dirEntry = QT_READDIR(dir); - if (dirEntry) { - fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name), QFileSystemEntry::FromNativePath()); - metaData.fillFromDirEnt(*dirEntry); - return true; + if (dirEntry) { + // process entries with correct UTF-8 names only + if (QFile::encodeName(QFile::decodeName(dirEntry->d_name)) == dirEntry->d_name) { + fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name), QFileSystemEntry::FromNativePath()); + metaData.fillFromDirEnt(*dirEntry); + return true; + } + } else { + break; + } } lastError = errno; -- cgit v1.2.3