-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map Adapter cannot handle Value whose representation can be zero bytes #3153
Comments
Thanks for reporting. Would you be able to write a repro situation in https://github.com/square/wire/tree/master/wire-gradle-plugin-playground/src/main for instance? You would add the proto file in the |
Sure, I will take a look this weekend, but looking at main it seems there is none of such tests exists |
No need to set up a test, you can write a main method and simply reproduce the crash. You can then copy/paste here the Something like fun main() {
val bytes = // the payload you mentioned in bytes or in JSON string if that's the problem
MyGeneratedClass.ADAPTER.decode(bytes) // this would throw
} To get the bytes you could also do something like |
Ok I tried to make example in pure kotlin with a very simple message
But it seems wire correctly serializes it omitting message and then deserializes it using following code: import human.MessageWithZeroValueMap
import human.ValidZeroMessage
fun main() {
println("Show that message itself is valid!")
val zero_message = ValidZeroMessage.Builder().meters(0.0f).build()
val zero_message_encoded = zero_message.encodeByteString()
println("Null message=$zero_message_encoded")
val decoded_zero_message = ValidZeroMessage.ADAPTER.decode(zero_message_encoded)
println("Decoded null message=$decoded_zero_message")
println("Now try to put it into map")
val values = mapOf("1" to decoded_zero_message)
val msg_map = MessageWithZeroValueMap.Builder().values(values).build()
println("Map with null message=$msg_map")
val msg_map_encoded = msg_map.encodeByteString()
println("Encoded map with null message=$msg_map_encoded")
val decoded_msg_map = MessageWithZeroValueMap.ADAPTER.decode(msg_map_encoded)
println("Decoded map message=$decoded_msg_map")
} I need to check out my example from work once again to see what could be missing |
@DoumanAsh all good. Thanks a lot for looking into it. |
Subj
If you use message like:
Wire will choke on parsing map with value initialized as:
That's because it will be encoded as zero bytes due to zero being treated as non-presence in case of integers and floats
Therefore it triggers this check to fail:
https://github.com/square/wire/blob/master/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoAdapter.kt#L812
Even though message itself is legit in protobuf 3
The text was updated successfully, but these errors were encountered: