Summary: | Cannot open file with non-ascii name when LC_ALL is not set | ||
---|---|---|---|
Product: | [Applications] dolphin | Reporter: | tusooa <tusooa> |
Component: | general | Assignee: | tusooa <tusooa> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | kfm-devel, luigi.toscano, nate |
Priority: | NOR | ||
Version: | 20.08.3 | ||
Target Milestone: | --- | ||
Platform: | Gentoo Packages | ||
OS: | Linux | ||
Latest Commit: | https://invent.kde.org/frameworks/kio/commit/0a13e0a3e830be2b2b2e5c2c6cf8cef25bd68bd8 | Version Fixed In: | 5.79 |
Sentry Crash Report: | |||
Attachments: |
Backtrace with /usr/bin/dolphin and system kio
Backtrace with the dolphin and kio I compiled in Debug mode |
Description
tusooa
2021-02-02 04:58:39 UTC
With no LC_ALL=en_CA.UTF-8, codec is "US-ASCII" mibEnum= 3 locale is "en_CA" , "en-CA" With LC_ALL=en_CA.UTF-8 the codec is set to UTF-8. Not sure why. QTextCodec gets the charset from ucnv_getDefaultName() which will return "US-ASCII" if setlocale(LC_ALL, "") is not called before that. https://bugreports.qt.io/browse/QTBUG-57522 describes how this case may happen. And it seems the Qt person refused to fix it. This may be the cause of this bug. Created attachment 135420 [details]
Backtrace with /usr/bin/dolphin and system kio
Created attachment 135421 [details]
Backtrace with the dolphin and kio I compiled in Debug mode
I used the following code to override ucnv_getDefaultName() to call std::terminate() and thus allow us to get a backtrace: ``` #include <exception> extern "C" const char *ucnv_getDefaultName(void) { std::terminate(); return ""; } ``` Compile it with `g++ ucnv-override.cpp -shared -fPIC -o ucnv-override.so` and set LD_PRELOAD=/path/to/ucnv-override.so , we get two backtraces: one with system dolphin and kio, another with those I compiled with debugging symbols. Replacing the static QLoggingCategory category("kf.kio.widgets.kdirmodel", QtInfoMsg); in kdirmodel.cpp with Q_LOGGING_CATEGORY(category, "kf.kio.widgets.kdirmodel", QtInfoMsg); resolves this bug. From https://doc.qt.io/qt-5/qloggingcategory.html#Q_LOGGING_CATEGORY-1 : "The implicitly-defined QLoggingCategory object is created on first use, in a thread-safe manner." The original way to explicitly define a static QLoggingCategory will lead to a call to ucnv_getDefaultName() before QApplication constructor (where setlocale() is called), thus making QTextCodec::codecForLocale() misbehave. Here we replace the explicit definition with the Q_LOGGING_CATEGORY macro, and thus avoid this problem. Git commit b3b545bb47b2dfbff3f88a60c0922bdb589f20ce by Tusooa Zhu. Committed on 04/02/2021 at 13:15. Pushed by tusooaw into branch 'tusooaw/432406-non-ascii-file'. Fix default codec being set to "US-ASCII" in KIO apps From https://doc.qt.io/qt-5/qloggingcategory.html#Q_LOGGING_CATEGORY-1 : "The implicitly-defined QLoggingCategory object is created on first use, in a thread-safe manner." The original way to explicitly define a static QLoggingCategory will lead to a call to ucnv_getDefaultName() before QApplication constructor (where setlocale() is called), thus making QTextCodec::codecForLocale() misbehave. Here we replace the explicit definition with the Q_LOGGING_CATEGORY macro, and thus avoid this problem. M +1 -1 src/widgets/kdirmodel.cpp https://invent.kde.org/frameworks/kio/commit/b3b545bb47b2dfbff3f88a60c0922bdb589f20ce As this is not yet merged, reopen this. It may not be the best policy, but bugs are marked RESOLVED/FIXED when the fix is merged, so let's keep it for consistency. (I may have heard the original plan was to use CLOSED/FIXED as the final-final state, but it never happened. Anyway the "Latest Commit" field should help). Tusooa meant that the branch has not yet been merged to master. The hookscript got confused because the branch was not prefixed with work/, so it interpreted the Bug: keyword to mean that this bug should be closed. (In reply to Nate Graham from comment #10) > Tusooa meant that the branch has not yet been merged to master. The > hookscript got confused because the branch was not prefixed with work/, so > it interpreted the Bug: keyword to mean that this bug should be closed. Yes, that is what i mean--Because in Krita people tend to name their branch prefixed with their username and I thought doing that will not trigger the closing of a bug, but looks like I messed up. Git commit 423bea37e4bb06b9c04a62a9a91b720ec5d5e3d5 by Tusooa Zhu. Committed on 04/02/2021 at 23:06. Pushed by tusooaw into branch 'master'. Use Q_LOGGING_CATEGORY macro instead of explicit QLoggingCategory Explicitly defining a QLoggingCategory will make QTextCodec::codecForLocale() misbehave, so we change it to Q_LOGGING_CATEGORY macro. M +1 -1 src/kpasswdserver/kpasswdserver.cpp M +1 -1 src/urifilters/ikws/kuriikwsfilter.cpp M +1 -1 src/urifilters/ikws/kuriikwsfiltereng.cpp M +1 -1 src/urifilters/ikws/kurisearchfilter.cpp M +1 -1 src/urifilters/localdomain/localdomainurifilter.cpp M +1 -1 src/urifilters/shorturi/kshorturifilter.cpp https://invent.kde.org/frameworks/kio/commit/423bea37e4bb06b9c04a62a9a91b720ec5d5e3d5 Git commit 0a13e0a3e830be2b2b2e5c2c6cf8cef25bd68bd8 by Tusooa Zhu. Committed on 04/02/2021 at 14:45. Pushed by tusooaw into branch 'master'. Fix default codec being set to "US-ASCII" in KIO apps From https://doc.qt.io/qt-5/qloggingcategory.html#Q_LOGGING_CATEGORY-1 : "The implicitly-defined QLoggingCategory object is created on first use, in a thread-safe manner." The original way to explicitly define a static QLoggingCategory will lead to a call to ucnv_getDefaultName() before QApplication constructor (where setlocale() is called), thus making QTextCodec::codecForLocale() misbehave. Here we replace the explicit definition with the Q_LOGGING_CATEGORY macro, and thus avoid this problem. M +1 -1 src/widgets/kdirmodel.cpp https://invent.kde.org/frameworks/kio/commit/0a13e0a3e830be2b2b2e5c2c6cf8cef25bd68bd8 |