Permalink
Browse files

Addresses a data bleeding issue with lift-json

  • Loading branch information...
1 parent 657eee8 commit ea81b2d25092ec03423f4d4645f64874a4c7d909 @dpp dpp committed with indrajitr Apr 5, 2013
@@ -376,7 +376,11 @@ object JsonParser {
}
}
- def near = new String(segment, (cur-20) max 0, (cur + 1) min Segments.segmentSize)
+ def near = {
+ val start = (cur - 20) max 0
+ val len = ((cur + 1) min Segments.segmentSize) - start
+ new String(segment, start, len)
+ }
def release = segments.foreach(Segments.release)
@@ -25,7 +25,18 @@ import org.scalacheck.Prop._
/**
* System under specification for JSON Parser.
*/
-object JsonParserSpec extends Specification("JSON Parser Specification") with JValueGen with ScalaCheck {
+object JsonParserSpec extends Specification with JValueGen with ScalaCheck {
+
+ private def parseBadThing(): String = try {
+ parse("""{"user":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"<}""")
+ "x" * 1000
+ } catch {
+ case e: Throwable => e.getMessage
+ }
+
+
+ "JSON Parser Specification".title
+
"Any valid json can be parsed" in {
val parsing = (json: JValue) => { parse(Printer.pretty(render(json))); true }
forAll(parsing) must pass
@@ -51,6 +62,15 @@ object JsonParserSpec extends Specification("JSON Parser Specification") with JV
parse("[\"abc\\\"\\\\\\/\\b\\f\\n\\r\\t\\u00a0\"]") must_== JArray(JString("abc\"\\/\b\f\n\r\t\u00a0")::Nil)
}
+
+ "Parser does not bleed prior results" in {
+ parse("""{"a": "now is the time for all good men to come to the aid of their dog and eat dog food with other dogs and bark and woof and do dog things. now is the time for all good men to come to the aid of their dog and eat dog food with other dogs and bark and woof and do dog things. now is the time for all good men to come to the aid of their dog and eat dog food with other dogs and bark and woof and do dog things. now is the time for all good men to come to the aid of their dog and eat dog food with other dogs and bark and woof and do dog things. now is the time for all good men to come to the aid of their dog and eat dog food with other dogs and bark and woof and do dog things. now is the time for all good men to come to the aid of their dog and eat dog food with other dogs and bark and woof and do dog things. now is the time for all good men to come to the aid of their dog and eat dog food with other dogs and bark and woof and do dog things.now is the time for all good men to come to the aid of their dog and eat dog food with other dogs and bark and woof and do dog things"}""")
+
+ val msg = parseBadThing()
+
+ msg.length must be_<=(50)
+ }
+
"Unclosed string literal fails parsing" in {
parseOpt("{\"foo\":\"sd") mustEqual None
parseOpt("{\"foo\":\"sd}") mustEqual None

0 comments on commit ea81b2d

Please sign in to comment.