mirror of
https://github.com/nlohmann/json.git
synced 2026-10-02 04:30:29 +00:00
Fix fuzzer driver step lists to match the checks the code performs
The header comment of six of the seven binary-format fuzzer drivers listed an invariant the code does not check: CBOR, MessagePack, BSON and BON8 said "assert(j1 == j2)", but the code checks byte stability, assert(to_X(j2) == vec). UBJSON and BJData still described the old "assert(j1 == j2/j3/j4)" byte-exact check from before PR #5494 replaced it with a use_size/use_type-aware round trip (UBJSON) and a value-stability check (BJData); BJData's added paragraph already explained the new check, but the step list above it did not. Also remove a dead branch in fuzzer-parse_bson.cpp: from_bson() is called with allow_exceptions = true, so it throws instead of returning a discarded value, and the "if (j1.is_discarded()) return 0;" guard could never trigger. Drop the unused <iostream> include from all seven drivers and <sstream> from all but fuzzer-parse_bon8.cpp, which is the only one that uses std::istringstream. Overlaps #5601, which edits all seven drivers in the same hunks. Closes #5714 item 4. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -11,15 +11,15 @@ This file implements a parser test suitable for fuzz testing. Given a byte
|
||||
array data, it performs the following steps:
|
||||
|
||||
- j1 = from_bjdata(data)
|
||||
- vec = to_bjdata(j1)
|
||||
- j2 = from_bjdata(vec)
|
||||
- assert(j1 == j2)
|
||||
- vec2 = to_bjdata(j1, use_size = true, use_type = false)
|
||||
- j3 = from_bjdata(vec2)
|
||||
- assert(j1 == j3)
|
||||
- vec3 = to_bjdata(j1, use_size = true, use_type = true)
|
||||
- j4 = from_bjdata(vec3)
|
||||
- assert(j1 == j4)
|
||||
- vec2 = to_bjdata(j1, use_size = false, use_type = false)
|
||||
- vec3 = to_bjdata(j1, use_size = true, use_type = false)
|
||||
- vec4 = to_bjdata(j1, use_size = true, use_type = true)
|
||||
- j2 = from_bjdata(vec2)
|
||||
- j3 = from_bjdata(vec3)
|
||||
- j4 = from_bjdata(vec4)
|
||||
- assert(from_bjdata(to_bjdata(j2, use_size = false, use_type = false)) is value-stable with j2)
|
||||
- assert(from_bjdata(to_bjdata(j3, use_size = true, use_type = false)) is value-stable with j3)
|
||||
- assert(from_bjdata(to_bjdata(j4, use_size = true, use_type = true)) is value-stable with j4)
|
||||
|
||||
Re-serializing j2/j3/j4 with the same use_size/use_type settings is checked
|
||||
for value-stability rather than byte-exact stability: from_bjdata(to_bjdata(j2))
|
||||
@@ -50,8 +50,6 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// the round-trip checks below are assertions; NDEBUG would compile them away
|
||||
|
||||
@@ -13,7 +13,7 @@ array data, it performs the following steps:
|
||||
- j1 = from_bon8(data)
|
||||
- vec = to_bon8(j1)
|
||||
- j2 = from_bon8(vec)
|
||||
- assert(j1 == j2)
|
||||
- assert(to_bon8(j2) == vec)
|
||||
|
||||
It also checks that reading the data from a stream, which reads strings byte by
|
||||
byte, gives the same value or error as reading it from contiguous memory, which
|
||||
@@ -24,7 +24,6 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
@@ -13,15 +13,13 @@ array data, it performs the following steps:
|
||||
- j1 = from_bson(data)
|
||||
- vec = to_bson(j1)
|
||||
- j2 = from_bson(vec)
|
||||
- assert(j1 == j2)
|
||||
- assert(to_bson(j2) == vec)
|
||||
|
||||
The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
|
||||
drivers.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// the round-trip checks below are assertions; NDEBUG would compile them away
|
||||
@@ -40,11 +38,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
std::vector<uint8_t> const vec1(data, data + size);
|
||||
json const j1 = json::from_bson(vec1);
|
||||
|
||||
if (j1.is_discarded())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// step 2: round trip
|
||||
|
||||
@@ -13,15 +13,13 @@ array data, it performs the following steps:
|
||||
- j1 = from_cbor(data)
|
||||
- vec = to_cbor(j1)
|
||||
- j2 = from_cbor(vec)
|
||||
- assert(j1 == j2)
|
||||
- assert(to_cbor(j2) == vec)
|
||||
|
||||
The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
|
||||
drivers.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// the round-trip checks below are assertions; NDEBUG would compile them away
|
||||
|
||||
@@ -21,8 +21,6 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// the round-trip checks below are assertions; NDEBUG would compile them away
|
||||
|
||||
@@ -13,15 +13,13 @@ array data, it performs the following steps:
|
||||
- j1 = from_msgpack(data)
|
||||
- vec = to_msgpack(j1)
|
||||
- j2 = from_msgpack(vec)
|
||||
- assert(j1 == j2)
|
||||
- assert(to_msgpack(j2) == vec)
|
||||
|
||||
The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
|
||||
drivers.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// the round-trip checks below are assertions; NDEBUG would compile them away
|
||||
|
||||
@@ -11,15 +11,15 @@ This file implements a parser test suitable for fuzz testing. Given a byte
|
||||
array data, it performs the following steps:
|
||||
|
||||
- j1 = from_ubjson(data)
|
||||
- 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)
|
||||
- vec2 = to_ubjson(j1, use_size = false, use_type = false)
|
||||
- vec3 = to_ubjson(j1, use_size = true, use_type = false)
|
||||
- vec4 = to_ubjson(j1, use_size = true, use_type = true)
|
||||
- j2 = from_ubjson(vec2)
|
||||
- j3 = from_ubjson(vec3)
|
||||
- j4 = from_ubjson(vec4)
|
||||
- assert(to_ubjson(j2, use_size = false, use_type = false) == vec2)
|
||||
- assert(to_ubjson(j3, use_size = true, use_type = false) == vec3)
|
||||
- assert(to_ubjson(j4, use_size = true, use_type = true) == vec4)
|
||||
|
||||
The unit tests run the same checks on a fixed corpus (see the "UBJSON round-trip
|
||||
invariants" test case), so keep both in sync.
|
||||
@@ -29,8 +29,6 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// the round-trip checks below are assertions; NDEBUG would compile them away
|
||||
|
||||
Reference in New Issue
Block a user