Closed hedon954 closed 3 months ago
The string "xxxx"
is not invalid protobuf, since x
indicates field 15 | type varint
and x
as a value indicates 120
.
One can get surprisingly long specifically crafted strings that are surprisingly valid Protobuf one I crafted before was: "*myFooIsStrangeAndWeirdButNotQuiteBroken..."
.
PS: if this wasn’t clear, this is “working as intended”, since it is technically validly encoded protobuf.
The string
"xxxx"
is not invalid protobuf, sincex
indicatesfield 15 | type varint
andx
as a value indicates120
.One can get surprisingly long specifically crafted strings that are surprisingly valid Protobuf one I crafted before was:
"*myFooIsStrangeAndWeirdButNotQuiteBroken..."
.PS: if this wasn’t clear, this is “working as intended”, since it is technically validly encoded protobuf.
Interesting! Thanks for your reply! 😄
What version of protobuf and what language are you using?
What did you do?
I've implemented a function to unmarshal byte slices into protobuf structures as shown below:
To verify the behavior of this function, I wrote some unit tests. Here are two cases, one of which behaves unexpectedly:
Here's the definition of
fixtures.Request
used in the tests:What did you expect to see?
I expected that unmarshaling
[]byte("xxxx")
into a protobuf structure would fail in a similar manner to unmarshaling[]byte("hello")
, given that both inputs are not valid protobuf serialized forms ofRequest
.What did you see instead?
Unexpectedly, the unmarshaling of
[]byte("xxxx")
did not result in an error. Instead, the function returned a structure withunknownFields
. This behavior is inconsistent and can lead to confusion among developers.