Skip to content
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

Properties serialization incorrect behavior #2887

Open
FerrumBrain opened this issue Dec 16, 2024 · 0 comments
Open

Properties serialization incorrect behavior #2887

FerrumBrain opened this issue Dec 16, 2024 · 0 comments

Comments

@FerrumBrain
Copy link

0. Setup

We created the following class hierarchy for testing serialization library:

Value (org.plan.research)
    ArrayValue (org.plan.research)
    BooleanArrayValue (org.plan.research)
    BooleanValue (org.plan.research)
    ByteArrayValue (org.plan.research)
    ByteValue (org.plan.research)
    CharArrayValue (org.plan.research)
    CharValue (org.plan.research)
    CompositeNullableValue (org.plan.research)
    DefaultValueAlways (org.plan.research)
    DefaultValueNever (org.plan.research)
    DoubleArrayValue (org.plan.research)
    DoubleValue (org.plan.research)
    EnumValue (org.plan.research)
    FloatArrayValue (org.plan.research)
    FloatValue (org.plan.research)
    IntArrayValue (org.plan.research)
    IntValue (org.plan.research)
    ListValue (org.plan.research)
    LongArrayValue (org.plan.research)
    LongValue (org.plan.research)
    NullValue (org.plan.research)
    ObjectValue (org.plan.research)
    ShortArrayValue (org.plan.research)
    ShortValue (org.plan.research)
    StringValue (org.plan.research)

Value hierarchy tries to use most of the available serialization API and test it on all main data types available on Kotlin/JVM.
The exact implementation details are not important in most cases. We will highlight interesting implementation details whenever necessary.

1. Empty primitive arrays are not serialized

Empty primitive arrays are not present in any way in the encoded string.
Documentation does not specify behavior in that case.

The same exception can be achieved with null value fields, but that behavior is documented.

@OptIn(ExperimentalSerializationApi::class)
@Test
fun `missing field for empty primitive array`() {
    val value: Value = BooleanArrayValue(booleanArrayOf())
    val strMap = Properties.encodeToStringMap(value)
    // Fails with
    // "kotlinx.serialization.MissingFieldException: Field 'value' is required for type with serial name 'org.plan.research.BooleanArrayValue', but it was missing"
    val decodedValue = Properties.decodeFromStringMap<Value>(strMap)
    assertTrue { value == decodedValue }
}

Bugs are found by fuzzing team @ PLAN Lab

Environment

  • Kotlin version: 2.0.20
  • Library version: 1.7.3
  • Kotlin platforms: JVM
  • Gradle version: 8.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants