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

ArrayIndexOutOfBoundsException in appendStringSlowPath when serializing escaped characters #1441

Closed
JBeet opened this issue Apr 28, 2021 · 0 comments
Assignees

Comments

@JBeet
Copy link

JBeet commented Apr 28, 2021

Describe the bug
An ArrayIndexOutOfBoundsException is thrown in appendStringSlowPath when serializing strings that contain many characters that wil be escaped in the generated JSON. It looks like this is caused by an insufficient ensureAdditionalCapacity(string.length + 2) in appendQuoted

To Reproduce

import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

fun main() {
    println(Json.encodeToString(SerializationTest("\"".repeat(100))))
}

@Serializable
data class SerializationTest(val s: String)

Expected behavior
String is successfully serialized as JSON, without error.

Environment

  • Kotlin version: 1.5.0
  • Library version: 1.2.0
  • Kotlin platforms: JVM
  • Gradle version: 6.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

4 participants
@qwwdfsad @JBeet @sandwwraith and others