JsonParser hangs on very long number
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 324
- Avg merge
- 4h 35m
- Merged PRs (30d)
- 30
Description
Parsing a very long number (1 M digits) with the native parser takes an unreasonable long time. It's reasonable that you cannot parse arbitrarily long numbers in JSON, but it would be nice if you could get a ParseException rather than hanging.
It seems to get stuck in the constructor of java.math.BigDecimal:
at java.math.BigInteger.<init>(BigInteger.java:405)
at java.math.BigDecimal.<init>(BigDecimal.java:541)
at java.math.BigDecimal.<init>(BigDecimal.java:739)
at scala.math.BigDecimal$.exact(BigDecimal.scala:125)
at scala.math.BigDecimal$.apply(BigDecimal.scala:283)
at org.json4s.ParserUtil$.parseDouble(ParserUtil.scala:206)
at org.json4s.native.JsonParser$Parser.parseValue$1(JsonParser.scala:239)
at org.json4s.native.JsonParser$Parser.nextToken(JsonParser.scala:292)
at org.json4s.native.JsonParser$$anonfun$1.apply(JsonParser.scala:159)
at org.json4s.native.JsonParser$$anonfun$1.apply(JsonParser.scala:117)
at org.json4s.native.JsonParser$.parse(JsonParser.scala:105)
at org.json4s.native.JsonParser$.parse(JsonParser.scala:61)
at org.json4s.native.JsonMethods$class.parse(JsonMethods.scala:13)
at org.json4s.native.JsonMethods$.parse(JsonMethods.scala:62)
Perhaps a sanity check of the length of the string before trying to parse it as number? Such as not longer than 1024 characters.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with org.json4s.ParserUtil.scala:206 and org.json4s.native.JsonParser.scala:239, where the stack trace shows the long number is converted. Reproduce with a roughly one-million-digit JSON number and verify that parsing raises ParseException promptly instead of spending an unreasonable time in BigDecimal construction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100