🔨 implemented MessagePack in binary_reader
This commit is contained in:
parent
3a34f2d82c
commit
b15fc13dd1
4 changed files with 567 additions and 502 deletions
1024
src/json.hpp
1024
src/json.hpp
File diff suppressed because it is too large
Load diff
|
@ -28,7 +28,6 @@ SOFTWARE.
|
||||||
|
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
#define private public
|
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
|
@ -1357,12 +1356,6 @@ TEST_CASE("CBOR regressions", "[!throws]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("improve code coverage")
|
|
||||||
{
|
|
||||||
// exotic edge case
|
|
||||||
CHECK_THROWS_AS(json::check_length(0xffffffffffffffffull, 0xfffffffffffffff0ull, 0xff), json::parse_error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("CBOR roundtrips", "[hide]")
|
TEST_CASE("CBOR roundtrips", "[hide]")
|
||||||
|
|
|
@ -1038,35 +1038,35 @@ TEST_CASE("MessagePack")
|
||||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error);
|
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error);
|
||||||
|
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcc})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcc})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 1 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcd})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcd})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 2 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 2 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 4 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 4 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 4 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 4 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 5: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 8 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 8 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 8 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 8 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 5: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 8 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 6: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 8 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 7: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 8 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 8: unexpected end of input");
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 8 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 9: unexpected end of input");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("unsupported bytes")
|
SECTION("unsupported bytes")
|
||||||
|
|
|
@ -638,13 +638,13 @@ TEST_CASE("regression tests")
|
||||||
std::vector<uint8_t> vec1 {0xcb, 0x8f, 0x0a};
|
std::vector<uint8_t> vec1 {0xcb, 0x8f, 0x0a};
|
||||||
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error);
|
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error);
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(vec1),
|
CHECK_THROWS_WITH(json::from_msgpack(vec1),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 8 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
|
||||||
|
|
||||||
// related test case: incomplete float32
|
// related test case: incomplete float32
|
||||||
std::vector<uint8_t> vec2 {0xca, 0x8f, 0x0a};
|
std::vector<uint8_t> vec2 {0xca, 0x8f, 0x0a};
|
||||||
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error);
|
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error);
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(vec2),
|
CHECK_THROWS_WITH(json::from_msgpack(vec2),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 4 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
|
||||||
|
|
||||||
// related test case: incomplete Half-Precision Float (CBOR)
|
// related test case: incomplete Half-Precision Float (CBOR)
|
||||||
std::vector<uint8_t> vec3 {0xf9, 0x8f};
|
std::vector<uint8_t> vec3 {0xf9, 0x8f};
|
||||||
|
@ -671,7 +671,7 @@ TEST_CASE("regression tests")
|
||||||
std::vector<uint8_t> vec1 {0x87};
|
std::vector<uint8_t> vec1 {0x87};
|
||||||
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error);
|
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error);
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(vec1),
|
CHECK_THROWS_WITH(json::from_msgpack(vec1),
|
||||||
"[json.exception.parse_error.110] parse error at 2: cannot read 1 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
|
||||||
|
|
||||||
// more test cases for MessagePack
|
// more test cases for MessagePack
|
||||||
for (auto b :
|
for (auto b :
|
||||||
|
@ -708,7 +708,7 @@ TEST_CASE("regression tests")
|
||||||
"[json.exception.parse_error.110] parse error at 1: unexpected end of input");
|
"[json.exception.parse_error.110] parse error at 1: unexpected end of input");
|
||||||
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error);
|
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error);
|
||||||
CHECK_THROWS_WITH(json::from_msgpack(vec2),
|
CHECK_THROWS_WITH(json::from_msgpack(vec2),
|
||||||
"[json.exception.parse_error.110] parse error at 1: cannot read 1 bytes from vector");
|
"[json.exception.parse_error.110] parse error at 1: unexpected end of input");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("issue #411 - Heap-buffer-overflow (OSS-Fuzz issue 366)")
|
SECTION("issue #411 - Heap-buffer-overflow (OSS-Fuzz issue 366)")
|
||||||
|
|
Loading…
Reference in a new issue