Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parse_ubjson_fuzzer #2182

Merged
merged 1 commit into from
Jun 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions test/src/fuzzer-parse_ubjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ array data, it performs the following steps:
- vec = to_ubjson(j1)
- j2 = from_ubjson(vec)
- assert(j1 == j2)
- vec2 = to_ubjson(j1, use_size = true, use_type = false)
- j3 = from_ubjson(vec2)
- assert(j1 == j3)
- vec3 = to_ubjson(j1, use_size = true, use_type = true)
- j4 = from_ubjson(vec3)
- assert(j1 == j4)

The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
drivers.
Expand All @@ -35,14 +41,24 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)

try
{
// step 2: round trip
std::vector<uint8_t> vec2 = json::to_ubjson(j1);
// step 2.1: round trip without adding size annotations to container types
std::vector<uint8_t> vec2 = json::to_ubjson(j1, false, false);

// step 2.2: round trip with adding size annotations but without adding type annonations to container types
std::vector<uint8_t> vec3 = json::to_ubjson(j1, true, false);

// step 2.3: round trip with adding size as well as type annotations to container types
std::vector<uint8_t> vec4 = json::to_ubjson(j1, true, true);

// parse serialization
json j2 = json::from_ubjson(vec2);
json j3 = json::from_ubjson(vec3);
json j4 = json::from_ubjson(vec4);

// serializations must match
assert(json::to_ubjson(j2) == vec2);
assert(json::to_ubjson(j2, false, false) == vec2);
assert(json::to_ubjson(j3, true, false) == vec3);
assert(json::to_ubjson(j4, true, true) == vec4);
}
catch (const json::parse_error&)
{
Expand Down