diff options
author | Mathias <mathias@spray.io> | 2014-10-28 12:23:29 +0100 |
---|---|---|
committer | Mathias <mathias@spray.io> | 2014-10-28 12:26:49 +0100 |
commit | c3bd8fe437f422e1314a1a2ecd45c1d8f16facaa (patch) | |
tree | b906ed4399a1ed5663c5363b2d37935df84c268f /src/main/scala/spray | |
parent | e694cd7861266265bf69cb26c262f15ae2bab99c (diff) | |
download | spray-json-c3bd8fe437f422e1314a1a2ecd45c1d8f16facaa.tar.gz spray-json-c3bd8fe437f422e1314a1a2ecd45c1d8f16facaa.tar.bz2 spray-json-c3bd8fe437f422e1314a1a2ecd45c1d8f16facaa.zip |
Fix OOE when parsing unterminated JSON strings, fixes #122
Diffstat (limited to 'src/main/scala/spray')
-rw-r--r-- | src/main/scala/spray/json/JsonParser.scala | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main/scala/spray/json/JsonParser.scala b/src/main/scala/spray/json/JsonParser.scala index 8e7a83e..ea48842 100644 --- a/src/main/scala/spray/json/JsonParser.scala +++ b/src/main/scala/spray/json/JsonParser.scala @@ -132,11 +132,13 @@ class JsonParser(input: ParserInput) { } private def `char`() = - cursorChar match { - case '"' => false + // simple bloom-filter that quick-matches the most frequent case of characters that are ok to append + // (it doesn't match control chars, EOI, '"', '?', '\', 'b' and certain higher, non-ASCII chars) + if (((1L << cursorChar) & ((31 - cursorChar) >> 31) & 0x7ffffffbefffffffL) != 0L) appendSB(cursorChar) + else cursorChar match { + case '"' | EOI => false case '\\' => advance(); `escaped`() - case c if cursorChar >= ' ' => appendSB(cursorChar) - case _ => false + case c => (c >= ' ') && appendSB(c) } private def `escaped`() = { |