🐛 fixing CBOR's indefinity length strings #961

Beside the fix discussed in #961, we also had to re-adjust a test case. It seems that it was failing before, and I "fixed" it to work with the broken implementation...
This commit is contained in:
Niels Lohmann 2018-02-06 20:43:03 +01:00
parent 556e30f759
commit 8b457ace25
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
5 changed files with 21 additions and 6 deletions

View file

@ -1381,7 +1381,7 @@ TEST_CASE("single CBOR roundtrip")
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
// parse MessagePack file
// parse CBOR file
std::ifstream f_cbor(filename + ".cbor", std::ios::binary);
std::vector<uint8_t> packed((std::istreambuf_iterator<char>(f_cbor)),
std::istreambuf_iterator<char>());
@ -1921,7 +1921,7 @@ TEST_CASE("examples from RFC 7049 Appendix A")
CHECK(json::parse("\"\\ud800\\udd51\"") == json::from_cbor(std::vector<uint8_t>({0x64, 0xf0, 0x90, 0x85, 0x91})));
// indefinite length strings
CHECK(json::parse("\"streaming\"") == json::from_cbor(std::vector<uint8_t>({0x7f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0xff})));
CHECK(json::parse("\"streaming\"") == json::from_cbor(std::vector<uint8_t>({0x7f, 0x65, 0x73, 0x74, 0x72, 0x65, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x67, 0xff})));
}
SECTION("arrays")

View file

@ -1408,4 +1408,19 @@ TEST_CASE("regression tests")
"path": "/a/b/c"}])"_json),
"[json.exception.out_of_range.403] key 'a' not found");
}
SECTION("issue #961 - incorrect parsing of indefinite length CBOR strings")
{
std::vector<uint8_t> v_cbor =
{
0x7F,
0x64,
'a', 'b', 'c', 'd',
0x63,
'1', '2', '3',
0xFF
};
json j = json::from_cbor(v_cbor);
CHECK(j == "abcd123");
}
}