🐛 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...
pull/957/head
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

@ -969,6 +969,8 @@ I deeply appreciate the help of the following people.
- [zerodefect](https://github.com/zerodefect) fixed a compiler warning.
- [Kert](https://github.com/kaidokert) allowed to template the string type in the serialization and added the possibility to override the exceptional behavior.
- [mark-99](https://github.com/mark-99) helped fixing an ICC error.
- [Patrik Huber](https://github.com/patrikhuber) fixed links in the README file.
- [johnfb](https://github.com/johnfb) found a bug in the implementation of CBOR's indefinite length strings.
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.

View File

@ -948,8 +948,7 @@ class binary_reader
string_t result;
while (get() != 0xFF)
{
unexpect_eof();
result.push_back(static_cast<char>(current));
result.append(get_cbor_string());
}
return result;
}

View File

@ -5768,8 +5768,7 @@ class binary_reader
string_t result;
while (get() != 0xFF)
{
unexpect_eof();
result.push_back(static_cast<char>(current));
result.append(get_cbor_string());
}
return result;
}

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");
}
}