spray / spray-json

A lightweight, clean and simple JSON implementation in Scala
Apache License 2.0
974 stars 190 forks source link

OutOfMemoryError when parsing an invalid JSON #122

Closed cvrabie closed 10 years ago

cvrabie commented 10 years ago

This seems to happen in 1.3.0.

scala> val s = """{"a":"B","c:789}"""
s: String = {"a":"B","c:789}

scala> s.parseJson
java.lang.OutOfMemoryError: Java heap space
  at java.util.Arrays.copyOf(Arrays.java:2367)
  at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
  at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
  at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:587)
  at java.lang.StringBuilder.append(StringBuilder.java:214)
  at spray.json.JsonParser.appendSB(JsonParser.scala:179)
  at spray.json.JsonParser.char(JsonParser.scala:138)
  at spray.json.JsonParser.string(JsonParser.scala:129)
  at spray.json.JsonParser.members$1(JsonParser.scala:76)
  at spray.json.JsonParser.object(JsonParser.scala:84)
  at spray.json.JsonParser.value(JsonParser.scala:59)
  at spray.json.JsonParser.parseJsValue(JsonParser.scala:43)
  at spray.json.JsonParser$.apply(JsonParser.scala:28)
  at spray.json.PimpedString.parseJson(package.scala:45)
  ... 18 elided

Note that the quote from the second field name (c), is not closed correctly. However I would expect a spray.json.JsonParser.ParsingException or a spray.json.DeserializationException instead.

sirthias commented 10 years ago

Oops. This indeed looks like a major bug! We'll need to get that fixed quickly.