icerpc-csharp icon indicating copy to clipboard operation
icerpc-csharp copied to clipboard

Configure protobuf decoding limits

Open pepone opened this issue 2 years ago • 3 comments

See:

https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.CodedInputStream#Google_Protobuf_CodedInputStream_RecursionLimit

Seems this limits are not exposed with the ReadOnlySequence API we are using

pepone avatar Oct 23 '23 09:10 pepone

Looking at the C# protobuf API and sources, the decoding limits can only be set with the CodecInputStream API, the ParseContext used by other overloads always uses the default limits.

If we want to use the CodecInputStream API, we need to wrap the ReadOnlySequence in a Stream and then create the CodecInputStream with the desired limits using CreateWithLimits https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.CodedInputStream#Google_Protobuf_CodedInputStream_CreateWithLimits_System_IO_Stream_System_Int32_System_Int32_

This means an additional allocation for the stream wrapping the read-only sequence.

pepone avatar Oct 26 '23 13:10 pepone

See a related issue in the grpc-dotnet repository:

  • https://github.com/grpc/grpc-dotnet/issues/1983

pepone avatar Nov 08 '23 17:11 pepone

I'd rather not wrap CodecInputStream.

Since this is a Protobuf C# issue, should we open an issue in https://github.com/protocolbuffers/protobuf/issues?q=is%3Aopen+is%3Aissue+label%3Ac%23?

bernardnormier avatar Nov 21 '23 20:11 bernardnormier