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
Serialising an object with a String field containing certain JSON crashes with java.lang.ArrayIndexOutOfBoundsException:
CrashingJsonSerializationTest > bar() FAILED
java.lang.ArrayIndexOutOfBoundsException: Index 128 out of bounds for length 128
at kotlinx.serialization.json.internal.JsonStringBuilder.appendStringSlowPath(JsonStringBuilder.kt:102)
at kotlinx.serialization.json.internal.JsonStringBuilder.appendQuoted(JsonStringBuilder.kt:61)
at kotlinx.serialization.json.internal.Composer.printQuoted(Composers.kt:42)
at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeString(StreamingJsonEncoder.kt:203)
at kotlinx.serialization.encoding.AbstractEncoder.encodeStringElement(AbstractEncoder.kt:65)
at CrashingJsonSerializationTest$MyObject$$serializer.serialize(CrashingJsonSerialisation.kt:13)
at CrashingJsonSerializationTest$MyObject$$serializer.serialize(CrashingJsonSerialisation.kt:13)
at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:211)
at kotlinx.serialization.json.Json.encodeToString(Json.kt:80)
at CrashingJsonSerializationTest.bar(CrashingJsonSerialisation.kt:10)
I tried to create a minimal input to reproduce the problem, based on the input we first experienced it with.
To Reproduce
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import org.junit.jupiter.api.Test
class CrashingJsonSerializationTest {
@Test
fun bar() {
val failingString = "{\"status\":123,\"message\":\"content\",\"path\":\"/here/beeeeeeeeeeee/dragoons/d63574f-705c-49dd-a6bc-c8d1e524eefd/\"}"
val o = MyObject(failingString)
System.err.println(Json.encodeToString(MyObject.serializer(), o))
}
@Serializable
data class MyObject(val text: String)
}
Describe the bug
Serialising an object with a String field containing certain JSON crashes with java.lang.ArrayIndexOutOfBoundsException:
I tried to create a minimal input to reproduce the problem, based on the input we first experienced it with.
To Reproduce
See a complete reproducible project at https://github.com/timorantalaiho/kotlin-json-crash .
Expected behavior
Object should be serialised with the String properly escaped.
Serialisation should not crash, regardless of the contents of the String.
Environment
The text was updated successfully, but these errors were encountered: