Repository navigation
Conversation
rtk aborted (SIGABRT, exit 134) when any argument contained bytes that are not valid UTF-8, before the wrapped command ran. Clap is not the culprit: it reads argv via args_os() and correctly reports InvalidUtf8. That error routes into run_fallback(), which then collected argv with std::env::args() — panicking on exactly the input that sent it there. The non-UTF-8 error path was itself non-UTF-8-unsafe. Read argv with args_os() and keep the OsString values for execution, so the wrapped tool receives the bytes the user typed. Lossy copies still drive matching, display and tracking, where text is all that is needed. Fixes rtk-ai#3025
|
|
This was referenced Jul 17, 2026
Merged
kylehgc
added a commit
to kylehgc/rtk
that referenced
this pull request
Jul 17, 2026
… tests Amendment to the adopted upstream rtk-ai#3027 fix, per the repo test rule (rust-patterns.md: tests use expect("reason"), never bare unwrap). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
kylehgc
added a commit
to kylehgc/rtk
that referenced
this pull request
Jul 17, 2026
fix(cli): adopt upstream rtk-ai#3027 — handle non-UTF-8 argv in raw-execution fallback
KuSh
requested changes
Jul 25, 2026
|
|
||
| #[test] | ||
| fn non_utf8_pattern_does_not_abort() { | ||
| let d = tempfile::tempdir().unwrap(); |
Collaborator
There was a problem hiding this comment.
As stated in rust-patterns.md:
tests use expect("reason"), never bare unwrap
Collaborator
|
Ping @georgyia. Aside from the nitpick, and once you’ve signed the CLA, this one can be merged |
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3025
Problem
Any argument containing non-UTF-8 bytes aborted rtk before the wrapped command ran:
Exit 134 (SIGABRT) under the release profile's
panic="abort", 101 under a debug build. Nativegrephandles the same bytes fine and reports1, so rtk turned a working command into a crash.Root cause
Not clap. Clap reads argv via
args_os()and correctly reportsInvalidUtf8— it never panics. That error routes intorun_fallback(), which then collected argv withstd::env::args(), panicking on exactly the input that sent it there. The non-UTF-8 error path was itself non-UTF-8-unsafe:std::env::args()unwraps each argument, so it aborts the moment argv holds bytes that are not valid UTF-8.Fix
std::env::args_os()and keep theOsStringvalues for execution, so the wrapped tool receives the bytes the user actually typed.Stringcopies for matching, display and tracking (RTK_META_COMMANDS,raw_command, TOMLlookup_cmd,record_parse_failure_silent), where text is all that is needed.Forwarding the raw bytes rather than lossily converting them is the deliberate part:
to_string_lossyalone would stop the abort, but the wrapped tool would then search for replacement characters and silently report zero matches — trading a loud crash for a wrong answer.Scoped to the one reachable site.
core::args_utils::restore_double_dashhas the samestd::env::args()call, but every non-UTF-8 argv is rejected by clap and funnelled intorun_fallbackbefore those callers run — verified by backtrace ongit diff --,cargo test --andgrep -c. It is a latent hazard rather than a live bug, so it is left for a follow-up rather than changed without a test that can fail.Known remaining edge: a command name (argv[0]) that is itself non-UTF-8 still degrades to a clean 127 instead of resolving, because
resolved_command()takes&str. Widening that signature ripples through many callers, and the outcome is graceful rather than an abort, so it is out of scope here.Verification
env.rs:876:51, matching the issue), then confirmed gone.rtk grep -creturns1— identical toLC_ALL=C grep -con the same bytes.tests/non_utf8_argv_test.rsfail on unfixed code and pass with the fix: no abort, byte-forwarding vs native grep, and a clean 127 on the spawn-failure path.echo,ls, missing command,gain --badtypo,git status).cargo fmt --all --checkclean,cargo clippy --all-targetszero warnings,cargo test --all2496 passed / 0 failed.Verified on Linux (
rust:latest); the tests are#![cfg(unix)]since they build argv from raw bytes viaOsStringExt::from_vec.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --allrtk grep -c $'\xc3\xa2\xe2\x80' <file>inspected against nativegrepHappy to contribute here — rtk is a genuinely interesting project, and I'm glad to adjust anything in this PR if you'd prefer a different scope or approach.