Skip to content

Child-process arguments with non-ASCII characters are garbled on Windows with R 4.1 and earlier #19649

Open

Description

@kevinushey

Found by reading the code while working on #19640; not reproduced.

Many call sites convert a path with string_utils::utf8ToSystem() before handing it to a child process, as the program path or an argument (e.g. SessionBuild.cpp, SessionQuarto.cpp, SessionCompilePdf.cpp, the pandoc and panmirror helpers), or before embedding it in R code run by a child R process (e.g. ScriptJob.cpp, SessionRPubs.cpp, SessionHTMLPreview.cpp).

On Windows, Win32ChildProcess builds the command line with string_utils::utf8ToWide() (src/cpp/core/system/Win32ChildProcess.cpp:534, :551), which expects UTF-8. With R 4.2 and later, RStudio runs rsession-utf8.exe, whose code page is UTF-8, so utf8ToSystem() is a no-op and this works. With R 4.1 and earlier it runs rsession.exe, where utf8ToSystem() converts to the system code page. utf8ToWide() then reads those code-page bytes as UTF-8, so a non-ASCII character such as é would reach the child as U+FFFD.

If that holds, the fix is to drop utf8ToSystem() wherever the result only goes to a child process. Environment variables look the same: core::system::setenv() also converts with utf8ToWide() (src/cpp/core/system/Win32Environment.cpp:141), yet RS_RPOSTBACK_PATH is set from utf8ToSystem() (src/cpp/session/SessionMain.cpp:2886).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions