Kotlin / kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Apache License 2.0
5.4k stars 620 forks source link

Specify and fix JSON parser for corner cases #173

Closed qwwdfsad closed 4 years ago

qwwdfsad commented 6 years ago

After running JSON parser over Go fuzzer corpus (https://github.com/dvyukov/go-fuzz-corpus/blob/master/json/corpus/), I've found the following issues:

1) Parser breaks on valid JSON such as {a:"\\\r0\n"}, {“foo”: “”‘“”}, {x: “{”} 2) Parser breaks on "strange" JSON such as {“X”: “foo”, “Y”} and {“”:“”,“”:“”,“”:“”,“”:“”}. Even though it's legal to fail on such inputs, GSON and Jackson don't.

We should 1) Run parser on the whole corpus and fix its behaviour for valid inputs 2) At least document behaviour on "invalid" inputs and compare it with GSON/Jackson/Moshi, decide whether we should be consistent with them

sandwwraith commented 6 years ago

@qwwdfsad check this small set of tests: https://github.com/Kotlin/kotlinx.serialization/blob/master/json/common/test/kotlinx/serialization/json/CornerCaseTest.kt There are some of cases you've presented and parser works normally. Or I didn't understand contents of cases correctly?

qwwdfsad commented 6 years ago

It's kinda strange, theses cases are from our internal review (from 28.06) I'll double check that with the whole JSON corpus

sandwwraith commented 6 years ago

I can see that you have here 'fancy macOS' quotes, while parser supports only standard quotes. Maybe the problem is in them?

qwwdfsad commented 4 years ago

Fixed in the latest stable release