Skip to content

fix(cli): stop aborting on non-UTF-8 argv bytes - #3224

Closed
mgwedd wants to merge 1 commit into
rtk-ai:developfrom
mgwedd:fix/argv-non-utf8-abort
Closed

mgwedd wants to merge 1 commit into
rtk-ai:developfrom
mgwedd:fix/argv-non-utf8-abort

Conversation

@mgwedd

@mgwedd mgwedd commented Jul 26, 2026 •

Copy link
Copy Markdown

Summary

  • run_fallback in src/main.rs called std::env::args(), which aborts the process when any argument is not valid UTF-8. Clap rejects such args first and routes to the fallback, so rtk grep -c $'\xc3\xa2\xe2\x80' reliably aborted with exit 134 before the wrapped command ever ran.
  • The fallback now collects args_os() into a Vec<OsString> and passes those to the wrapped command, so the original bytes reach it unchanged; a lossy Vec<String> is derived only for the display, tracking, and TOML-filter-lookup strings. restore_double_dash in src/core/args_utils.rs had the same env::args() call and got the same treatment. No std::env::args() calls remain in src/.
  • Converting everything with to_string_lossy would also have stopped the abort, but it would have silently replaced the bytes passed to the underlying command. The raw OsStrings are kept on the execution path deliberately; the second test below pins that behavior.

Fixes #3025.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • Manual testing: rtk <command> output inspected

New tests/non_utf8_argv_test.rs (unix-only, since Windows argv is UTF-16) adds two tests:

  • non_utf8_arg_does_not_abort — asserts rtk doesn't panic or get killed by a signal when given a non-UTF-8 argument. This is how I reprod the reported panic initially.
  • non_utf8_arg_reaches_the_wrapped_command_verbatim — proves the invalid bytes reach the wrapped command unchanged (would fail if the fix used a lossy conversion instead of keeping raw OsStrings).

Both tests were red on develop baseline and green after this fix.

Gate results: cargo fmt --all --check clean, cargo clippy --all-targets no warnings, cargo test --all 2566 passed / 0 failed. rtk printf '%s' hello still behaves normally.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you!

@rtk-release-bot rtk-release-bot Bot closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic (SIGABRT, exit 134) on non-UTF-8 bytes in argv — std::env::args() unwrap

1 participant