fullstorydev / grpcurl

Like cURL, but for gRPC: Command-line tool for interacting with gRPC servers
MIT License
10.75k stars 502 forks source link

incorrect decoding of map keys in the response message #278

Closed shalamai closed 2 years ago

shalamai commented 2 years ago

hey, i experienced a weird bug i get wrong response if map key contains non-ascii character

steps to reproduce:

write grpc server with such endpoint:

  1. it returns a map e.g.

    message HelloResponse {
    map<string, string> map = 1;
    }
  2. a key of the map contains a non ascii character (character which is represented via more than one byte in utf-8) e.g. ❤ https://unicode-table.com/en/2764/

    {
    "map": { 
    "❤": "map value"
    }
    }

expected response (i get it when i call it with other grpc libraries)

{
  "map": { 
    "❤": "map value"
  }
}

actual response

{
  "map": {
    "\342\235\244": "map value"
  }
}

p.s. \342\235\244 is an octal representation of ❤ https://unicode-table.com/en/2764/

shalamai commented 2 years ago

UPD: i debugged a bit and found out that grpculr is fine. the library grpcdynamic from protoreflect that you use to make the actual grpc call here returns wrong response will debug that library. seem like the issue is there

shalamai commented 2 years ago

found the issue in protoreflect: https://github.com/jhump/protoreflect/issues/480

shalamai commented 2 years ago

fixed