Repository navigation
Decode command line arguments as UTF-8 so non-ANSI project names open - #11985
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Advanced Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 3e5163edecb580eb65910005d80b4bf6b71f19d4 and e19f84d9af780e4b4f7581c44d329e4bd0a9995c. 📒 Files selected for processing (2)
💤 Files with no reviewable changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
Priority: ➖ Normal — Schedule the Unicode filename fix because it addresses medium-severity failures opening macOS projects with Japanese, Cyrillic, and other non-ANSI paths on Windows. Estimated code review effort: 2 (Simple) | ~10 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The update enables UTF-8 command-line project paths and preserves the SQLite filename buffer during database opening. No current merge-blocking risk is identified. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Warning Linked repositories: Public OSS repositories can only analyze public repositories installed in this organization. No linked repositories were analyzed; skipped Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@jonata please remove or rewrite comments in the code, there is no need to be that verbose. |
|
Comments removed, thanks! 🫡 |
Opening a project whose name contains characters outside the Windows ANSI code page failed: Cyrillic, CJK and anything else non-ANSI arrived mangled and the file could not be found. prepareArguments() decoded argv with QString::fromLocal8Bit(), but every producer hands it UTF-8. main.cpp rebuilds argv from CommandLineToArgvW through QString::toUtf8() on Windows - with a comment saying it does so precisely to avoid losing characters that do not fit the local code page - and then reads those same buffers back with fromUtf8() at line 195. GuiApp::makeContextOptions builds them from muse::StringList, also UTF-8. The parser was the one place reading them as anything else. On Windows in Qt 6 that means the process ANSI code page, so the UTF-8 bytes of "тест.aup4" are re-read as CP1251 and become mojibake. Off Windows, QLocal8Bit::convertToUnicode is literally QUtf8::convertToUnicode (qstringconverter_p.h), so this changes nothing on Linux or macOS and is the correct decode everywhere. Three routes reach it: the process command line (double-clicking a project), the single instance handoff, and the in-app route that opens a project in a new window when one is already open. Note that QTextCodec::setCodecForLocale(UTF-8) in main.cpp does not protect this. It is a Qt 5 mechanism; Qt 6 routes fromLocal8Bit through QStringConverter::System in QtCore, which never consults it.
OpenStepByStep did
const char* name = fileName.ToUTF8();
ToUTF8() returns a wxScopedCharBuffer by value. Where wxString is not
internally UTF-8 - which is Windows and macOS - that buffer owns its memory and
is freed at the end of the declaration, so `name` dangles before either of the
two sqlite3_open calls that use it reads it.
It usually survives, because nothing allocates between the free and the reads,
which is why this has not been obviously broken. It is still a read of freed
memory on the path that opens every project.
The buffer is now held in a named variable for as long as the pointer is used.
ProjectFileIO::ReadThumbnail already does this correctly by calling
uri.ToUTF8().data() inside the call, where the temporary lives to the end of
the full expression.
e19f84d to
a52b0c2
Compare
Decode command line arguments as UTF-8 so non-ANSI project names open (#11985)
Resolves: #11976
Related: #11973
Project names containing characters outside the Windows ANSI code page —
Cyrillic, Japanese, CJK generally — could not be opened.
The defect
prepareArguments()decodedargvwithQString::fromLocal8Bit(), but everyproducer hands it UTF-8:
main.cpp:137—CommandLineToArgvW→QString::toUtf8()guiapp.cpp:41—muse::StringList::toStdStringList()argvmain.cpp:195reads the same buffers back withfromUtf8(). The parser wasthe only place reading them as something else.
On Windows in Qt 6,
fromLocal8Bitdecodes with the process ANSI code page, sothe UTF-8 bytes of
тест.aup4are re-read as CP1251 and become mojibake — whichis exactly what #11976 describes ("Audacity tries to access the file using a
corrupted (mojibake) filename").
Off Windows this changes nothing at all. From Qt 6.10.1's own header:
So
fromUtf8is correct on all three platforms, and a no-op on two of them.Three routes reach the parser and were all affected: double-clicking a project,
the single-instance handoff (
guiapp.cpp:162), and the in-app route that opensa project in a new window when one is already open
(
projectactionscontroller.cpp:997).QTextCodec::setCodecForLocale(UTF-8)inmain.cpp:127does not protectagainst this. It is a Qt 5 mechanism; Qt 6 routes
fromLocal8BitthroughQStringConverter::Systeminside QtCore, which never consultsQTextCodec(a separate Qt5Compat module). It is worth deleting, but I have left it alone
here rather than widen the change.
Second commit: a dangling buffer on the same open path
While tracing this I found unrelated but real UB in
DBConnection::OpenStepByStep:ToUTF8()returns awxScopedCharBufferby value; wherewxStringis notinternally UTF-8 (Windows, macOS) it owns its memory. It usually survives
because nothing allocates in between, which is why it has not been obviously
broken — but it is a read of freed memory on the path that opens every project.
ProjectFileIO::ReadThumbnailalready does this correctly by callinguri.ToUTF8().data()inside the call.On #11973 — why "Related" and not "Resolves"
#11973 (Cyrillic name, fails on first attempt, works on the second) is very
likely the same defect: the in-app new-window route sends the path through the
parser on the first attempt, and the second attempt — with no project open —
opens in-process and never touches it. That fits the reported asymmetry exactly.
But the second screenshot in that issue shows the Cyrillic name rendered
correctly in "Failed to open database file: …тест.aup4", which is not what a
mojibake path would produce. So either the message is built from a different
string than the one used to open, or something else is involved — possibly the
dangling buffer above. I have not claimed to resolve it.
Verification, and its limits
Both reports are Windows-only and this was developed on Linux, where
fromLocal8Bitis already UTF-8 — so I cannot demonstrate either fixworking. What I can show:
(
Open(…тест.wav) succeeded), confirming no regression where the code pathwas already correct.
ctestgreen, codestyle clean.This needs testing on Windows with a non-ANSI project name before it should be
trusted.
Recommended:
QA: