Skip to content

fix(grpc): Fix handling of non-UTF-8 strings in target URI path#2677

Open
arjan-bal wants to merge 6 commits into
grpc:masterfrom
arjan-bal:non-utf-strings
Open

fix(grpc): Fix handling of non-UTF-8 strings in target URI path#2677
arjan-bal wants to merge 6 commits into
grpc:masterfrom
arjan-bal:non-utf-strings

Conversation

@arjan-bal
Copy link
Copy Markdown
Contributor

In Rust, standard strings must hold valid UTF-8 data. While there are types to represent non-UTF-8 strings in the standard library, they are currently unstable.

This PR ensures that non-UTF-8 strings are correctly parsed from the target URI path and propagated through the channel.

Key Changes:

  • Updates ByteStr semantics: The UTF-8 invariant on the ByteStr type in the gRPC crate has been dropped, allowing it to store arbitrary bytes. I also implemented common traits to support string-like operations and cross-type comparisons. This enables resolver Address types to hold arbitrary byte sequences.
  • Modified Target::path(): This function now percent-decodes the path and returns a ByteStr instead of an &str.
  • Updated Unix socket tests: Because Unix file paths can contain non-UTF-8 characters, the tests have been updated to verify that these byte sequences propagate correctly through the channel.

Notes on Authority and UTF-8:

The Authority struct and the channel option's override_authority function continue to use standard strings, as they map to the HTTP/2 :authority pseudo-header (which must be valid UTF-8).

In the default ResolverBuilder::default_authority implementation, the path is now converted to a string using String::from_utf8_lossy. To prevent potential data loss, resolver implementations can override this trait method to handle invalid UTF-8 sequences as needed.

@arjan-bal arjan-bal requested a review from dfawley June 5, 2026 17:44
@arjan-bal arjan-bal changed the title fix(grpc): Fix handling of non-UTF-8 path strings in target URI fix(grpc): Fix handling of non-UTF-8 strings in target URI path Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants