Skip to content

Windows: a non-UTF-8 argument bypasses MSYS/Cygwin quoting via to_str() == None #4116

Open

Description

@KuSh

push_child_arg in src/core/utils.rs decides whether to re-encode an argument by going through str:

match arg.to_str() {
    Some(s) if s.contains('"') && !is_batch_program(cmd) => { /* re-encode */ }
    _ => { cmd.arg(arg); }
}

On Windows an OsStr is WTF-8, so to_str() returns None for an argument holding an unpaired surrogate. Such an argument silently falls through to std's encoding — which is exactly the encoding #3727 is about — so if it also contains a ", it reaches an MSYS/Cygwin child mangled, with no diagnostic.

Why it is reachable. The one converted call site that actually carries OsStrings rather than Strings is runner::run_passthrough(tool: &str, args: &[std::ffi::OsString], ..) (src/core/runner.rs), whose arguments come from clap's args_os and are therefore not pre-validated as UTF-8 the way std::env::args() would be.

Severity. Low. The fallback is today's behaviour, not something worse, and it needs an unpaired surrogate and a double quote in the same argument. Filing it so it is not lost, not because it should hold anything up.

Fix shape. Test the bytes instead of the str, and build the raw argument from the wide encoding, so no UTF-8 round trip is needed:

arg.as_encoded_bytes().contains(&b'"')          // instead of to_str()
std::os::windows::ffi::OsStrExt::encode_wide(arg)  // to build the raw argument

Found while reviewing #3728, which introduced push_child_arg; noted there as a non-blocking item. The ChildCommand prototype in #4103 inherits the same to_str() gate, so whichever of the two lands should carry the fix.

Searched open and closed issues under three wordings ("non-UTF-8 argument Windows OsString", "to_str OsStr lossy args_os", "unpaired surrogate invalid unicode argument") before filing; nothing existed.

Activity

  1. added
    bug
    help wanted
    on Sep 18, 2026
  2. rtk-wshm-sync-bot commented on Sep 18, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟢 Priority low
    🎯 Confidence 85%

    Summary

    push_child_arg uses to_str() to gate MSYS/Cygwin quote re-encoding, so non-UTF-8 (unpaired surrogate) Windows args silently skip quoting if they also contain a double quote; switch to as_encoded_bytes()/encode_wide() to avoid the UTF-8 round trip.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/core/utils.rs
    • src/core/runner.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. added 3 commits that reference this issue on Sep 28, 2026
    385b21e
    ce89f2f
    5a2afe1
  4. added 12 commits that reference this issue on Oct 8, 2026
    d826331
    fd4c6dd
    90dbe9d
    3da8837
    aa57322
    a94dd92
    eaa3fda
    cba780a
    7a137fe
    e4917d2
    8034dd1
    ac507f1
  5. added a commit that references this issue on Oct 29, 2026
    a3bcacb
  6. added 5 commits that reference this issue on Nov 17, 2026
    863d5ce
    ddcf77b
    de78669
    577c220
    e36369a
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

    area:clibughelp wantedplatform:windowspriority:low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions