Commit 672615f5 authored by Kenton Varda's avatar Kenton Varda

Merge pull request #270 from eriksjolund/check_num_remaining_bytes_of_escaped_json_character

Check num remaining bytes of escaped json character
parents b57cbcd6 f869e757
...@@ -410,6 +410,7 @@ KJ_TEST("basic json decoding") { ...@@ -410,6 +410,7 @@ KJ_TEST("basic json decoding") {
KJ_EXPECT_THROW_MESSAGE("Unexpected input", json.decodeRaw("a", root)); KJ_EXPECT_THROW_MESSAGE("Unexpected input", json.decodeRaw("a", root));
KJ_EXPECT_THROW_MESSAGE("ends prematurely", json.decodeRaw("[", root)); KJ_EXPECT_THROW_MESSAGE("ends prematurely", json.decodeRaw("[", root));
KJ_EXPECT_THROW_MESSAGE("ends prematurely", json.decodeRaw("{", root)); KJ_EXPECT_THROW_MESSAGE("ends prematurely", json.decodeRaw("{", root));
KJ_EXPECT_THROW_MESSAGE("ends prematurely", json.decodeRaw("\"\\u\"", root));
KJ_EXPECT_THROW_MESSAGE("Unexpected input", json.decodeRaw("[}", root)); KJ_EXPECT_THROW_MESSAGE("Unexpected input", json.decodeRaw("[}", root));
KJ_EXPECT_THROW_MESSAGE("Unexpected input", json.decodeRaw("{]", root)); KJ_EXPECT_THROW_MESSAGE("Unexpected input", json.decodeRaw("{]", root));
KJ_EXPECT_THROW_MESSAGE("Unexpected input", json.decodeRaw("[}]", root)); KJ_EXPECT_THROW_MESSAGE("Unexpected input", json.decodeRaw("[}]", root));
......
...@@ -616,6 +616,7 @@ public: ...@@ -616,6 +616,7 @@ public:
case 't' : decoded.add('\t'); advance(); break; case 't' : decoded.add('\t'); advance(); break;
case 'u' : case 'u' :
advance(); // consume 'u' advance(); // consume 'u'
KJ_REQUIRE(remaining.size() >= 4, "JSON message ends prematurely.");
unescapeAndAppend(kj::arrayPtr(remaining.begin(), 4), decoded); unescapeAndAppend(kj::arrayPtr(remaining.begin(), 4), decoded);
advance(4); advance(4);
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment