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

JSON decodeFromString never terminates with some invalid inputs (JsonLexer.skipElement loops infinitely) => huge battery drain. #1474

Closed
valeriyo opened this issue May 12, 2021 · 2 comments
Assignees

Comments

@valeriyo
Copy link

Duplicating from https://youtrack.jetbrains.com/issue/KT-46611

Using Kotlin 1.5.0 with org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.0 (latest)

Given:

@Serializable
class Something

val json = Json { ignoreUnknownKeys = true }

.. this expression never terminates (with an exception) as it should, because the input is not valid JSON:

json.decodeFromString(Something.serializer(), """{"a":[{"b":[{"c":{}d",""e"":"}]}""")

Looks like the JsonLexer hits the end of input string, thus consumeNextToken() returns TC_EOF. After that, the while loop inside skipElement() keeps spinning forever.

@sandwwraith
Copy link
Member

Have it worked with 1.1.0? Seems that is a general bug, not a regression....

sandwwraith added a commit that referenced this issue May 12, 2021
Improve EOF exception in consumeStringLenient

Fixes #1474
sandwwraith added a commit that referenced this issue May 12, 2021
Improve EOF exception in consumeStringLenient

Fixes #1474
@valeriyo
Copy link
Author

I wouldn't know, but since 1.2.0 generates garbage (#1455) -- I hit this issue.

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

3 participants