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
It is slightly modified version of Value: added necessary annotations, unified types of lists and maps, added default value.
1. Empty messages can be decoded from various sources
If we try to deserialize some strings we will get empty message even if input wasn't empty.
val bytes = byteArrayOf(9)
val message =ProtoBuf.decodeFromByteArray<ProtobufMessage<Int>>(bytes)
assertTrue { bytes.contentEquals(ProtoBuf.encodeToByteArray(message)) } // Fails
2. Equal messages are encoded differently depending on type
If we try to serialize message with default values inclusion that is based on strings and message that is based on integers, we will get different results. And it works for all non-primitive and primitive types.
val messageInt =ProtobufMessage<Int>(
intFieldDefault =null,
intFieldFixed =null,
intFieldSigned =null,
// longField is 5 by default
floatField =null,
doubleField =null,
stringField =null,
booleanField =null,
enumField =null,
nestedMessageField =null,
oneOfField =null,
listField = emptyList(),
packedListField = emptyList(),
mapField = emptyMap(),
packedMapField = emptyMap(),
)
val messageString = messageInt asProtobufMessage<String>
val serializer =ProtoBuf { encodeDefaults =true }
val bytesForPrimitiveMessage = serializer.encodeToHexString<ProtobufMessage<Int>>(messageInt)
val bytesForNonPrimitiveMessages = serializer.encodeToHexString<ProtobufMessage<String>>(messageString)
assertTrue {bytesForPrimitiveMessage == bytesForNonPrimitiveMessages} // Fails
3. Decoding-encoding transformation is not an identity
For some not empty messages we can find byte sequence that will be decoded as a message that encodes into a different byte array.
val bytes = byteArrayOf(-30, 125, 0, 125)
val serializer =ProtoBuf { encodeDefaults =true }
val message = serializer.decodeFromByteArray<ProtobufMessage<ProtobufMessageInt>>(bytes)
assertTrue { bytes.contentEquals(serializer.encodeToByteArray(message)) } // Fails
4. Null cannot be assigned to a field with default value
If a field has default value you can't assign null to it. Even if null is default value, even if encodeDefaults is false
0. Setup
We will use the following structure of a Message:
It is slightly modified version of
Value
: added necessary annotations, unified types of lists and maps, added default value.1. Empty messages can be decoded from various sources
If we try to deserialize some strings we will get empty message even if input wasn't empty.
2. Equal messages are encoded differently depending on type
If we try to serialize message with default values inclusion that is based on strings and message that is based on integers, we will get different results. And it works for all non-primitive and primitive types.
3. Decoding-encoding transformation is not an identity
For some not empty messages we can find byte sequence that will be decoded as a message that encodes into a different byte array.
4. Null cannot be assigned to a field with default value
If a field has default value you can't assign null to it. Even if null is default value, even if encodeDefaults is false
Bugs are found by fuzzing team @ PLAN Lab
Environment
The text was updated successfully, but these errors were encountered: