diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2019-09-17 07:35:26 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2019-09-24 18:24:00 -0700 |
commit | 70e6e9fe590590f602dee230a64870365d9301aa (patch) | |
tree | 0a318475b92b14a3c23020fc115be96bbacc1a07 /src/corelib/io/qfilesystemiterator_unix.cpp | |
parent | 06cc5d307177ebacf8e6926b9690c12703004a1a (diff) |
Filesystem: avoid crashes on exit in case the locale codec is null
On exit, QLocale::codecForLocale() can return null as the codec may have
already been destroyed. In that case, pretend that Latin1 was the
locale, so any file name is acceptable. This matches QString:
QTextCodec *codec = QTextCodec::codecForLocale();
if (codec)
return codec->toUnicode(str, size);
#endif // textcodec
return fromLatin1(str, size);
Note that if we're wrong and the locale was *not* Latin1, files that you
had a name to may not be encoded or decoded the same way.
Fixes: QTBUG-78446
Change-Id: Iece6e011237e4ab284ecfffd15c54077728a17ca
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/io/qfilesystemiterator_unix.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemiterator_unix.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/io/qfilesystemiterator_unix.cpp b/src/corelib/io/qfilesystemiterator_unix.cpp index 92ebdf0341..0d178d062a 100644 --- a/src/corelib/io/qfilesystemiterator_unix.cpp +++ b/src/corelib/io/qfilesystemiterator_unix.cpp @@ -69,7 +69,9 @@ static bool checkNameDecodable(const char *d_name, qsizetype len) # ifdef QT_LOCALE_IS_UTF8 int mibEnum = 106; # else - int mibEnum = codec->mibEnum(); + int mibEnum = 4; // Latin 1 + if (codec) + mibEnum = codec->mibEnum(); # endif if (Q_LIKELY(mibEnum == 106)) // UTF-8 return QUtf8::isValidUtf8(d_name, len).isValidUtf8; |