diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2019-09-17 07:35:26 -0700 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2019-10-09 20:08:48 +0200 |
commit | f2e9505aa164f851ff4e121a209c9f9ae52041ae (patch) | |
tree | b1f3b0c5fe011afc7973db06c53c361edeadbcf0 | |
parent | 41e59afc4129260f783553777ef8a2092df1192c (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>
(cherry picked from commit 70e6e9fe590590f602dee230a64870365d9301aa)
-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; |