You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What version of protobuf and what language are you using?
Version: d04d7b1
I expected that passing in marshaled proto of one type of message to another with different fields would fail
as protobuf seems to promise. I am writing a package to ensure safety for a system that's trying to carefully
switch to entirely using protobufs, and requires flagging when the wrong messages come down the wrong service.
$ go run main.go
proto: no encoder for state impl.MessageState [GetProperties]
proto: no encoder for sizeCache int32 [GetProperties]
proto: no encoder for unknownFields []uint8 [GetProperties]
proto: no encoder for state impl.MessageState [GetProperties]
proto: no encoder for sizeCache int32 [GetProperties]
proto: no encoder for unknownFields []uint8 [GetProperties]
panic: proto: bad wiretype for field gen.Customer1.Name: got wiretype 0, want 2
goroutine 1 [running]:
main.main()
/Users/emmanuelodeke/go/src/github.com/orijtech/experiments/main.go:26 +0x430
exit status 2
This behavior surprised me quite a bit.
The text was updated successfully, but these errors were encountered:
odeke-em
changed the title
proto: mismatched field tags in messages doesn't an error when proto.Unmarshal returns
proto: mismatched field tags in messages doesn't an error in unrelated message and proto.Unmarshal returns a partially filled message
Jun 27, 2020
The current behavior is "correct". The defacto standard of correctness is generally what the C++ implementation does, which operates by putting fields with the wrong wire type in the unknown fields section. Certainly debatable whether that should have been done, but it is what it currently is and unlikely to change.
Thank you for the response @dsnet and great to catch you here!
Could we perhaps ask the rest of the protobuf team to document this problem? I haven't find any references to it, yet most users expect that they should get an error.
The protobuf team is aware of the relatively unspecified nature of protobufs themselves. See protocolbuffers/protobuf#6188. It doesn't seem to be a high priority for them to come up with a specification.
Closing as inactionable; the situation is unfortunate. The protobuf wire format is surprisingly lax and will accept all sorts of input as valid. It's actually surprisingly hard to get the parser to fail. Since we (the Go library team) aren't responsible for the protobuf specification itself, there's not much we can do.
What version of protobuf and what language are you using?
Version: d04d7b1
I expected that passing in marshaled proto of one type of message to another with different fields would fail
as protobuf seems to promise. I am writing a package to ensure safety for a system that's trying to carefully
switch to entirely using protobufs, and requires flagging when the wrong messages come down the wrong service.
TL;DR:
while the rest of the *golang/protobuf/proto packages fail:
Investigation
Given this proto below
In code if I accidentally unmarshal to a different struct, there isn't an error returned
When run with
google.golang.org/protobuf/proto
Unexpectedly succeeds
github.com/golang/protobuf/proto
Unexpectedly succeeds
github.com/gogo/protobuf/proto
Fails which is my expectation
This behavior surprised me quite a bit.
The text was updated successfully, but these errors were encountered: