From 9e6db177053740532b2e4985924e9ec633648178 Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Thu, 14 Nov 2024 14:22:17 -0500 Subject: [PATCH] Addressed some VS code analysis warnings --- include/jsoncons/json_reader.hpp | 1 - .../jsonschema/common/keyword_validators.hpp | 6 +- test/corelib/src/JSONTestSuite_tests.cpp | 8 +- ...nimized-fuzz_cbor_encoder-4729089884225536 | Bin 0 -> 12 bytes ...mized-fuzz_ubjson_encoder-6542820946542592 | Bin 0 -> 43968 bytes .../src/fuzz_regression_tests.cpp | 136 ++++++++++++------ 6 files changed, 100 insertions(+), 51 deletions(-) create mode 100644 test/fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_cbor_encoder-4729089884225536 create mode 100644 test/fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_ubjson_encoder-6542820946542592 diff --git a/include/jsoncons/json_reader.hpp b/include/jsoncons/json_reader.hpp index 4cd73e381c..868e5eab7f 100644 --- a/include/jsoncons/json_reader.hpp +++ b/include/jsoncons/json_reader.hpp @@ -184,7 +184,6 @@ namespace jsoncons { : basic_json_reader(std::forward(source), default_visitor_, options, - options.err_handler(), temp_alloc) { } diff --git a/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp b/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp index 164797b9ea..0b5069223e 100644 --- a/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp +++ b/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp @@ -39,7 +39,8 @@ namespace jsonschema { public: recursive_ref_validator(const Json& schema, const uri& schema_location) - : keyword_validator_base("$recursiveRef", schema, schema_location) + : keyword_validator_base("$recursiveRef", schema, schema_location), + tentative_target_(nullptr) {} uri get_base_uri() const @@ -136,7 +137,8 @@ namespace jsonschema { public: dynamic_ref_validator(const Json& schema, const uri& schema_location, const uri_wrapper& value) - : keyword_validator_base("$dynamicRef", schema, schema_location), value_(value) + : keyword_validator_base("$dynamicRef", schema, schema_location), value_(value), + tentative_target_(nullptr) { //std::cout << "dynamic_ref_validator path: " << schema_location.string() << ", value: " << value.string() << "\n"; } diff --git a/test/corelib/src/JSONTestSuite_tests.cpp b/test/corelib/src/JSONTestSuite_tests.cpp index 674d9075b2..4311b102d5 100644 --- a/test/corelib/src/JSONTestSuite_tests.cpp +++ b/test/corelib/src/JSONTestSuite_tests.cpp @@ -33,8 +33,8 @@ TEST_CASE("JSON Parsing Test Suite") if (fs::exists(p) && fs::is_regular_file(p) && p.path().extension() == ".json" && p.path().filename().c_str()[0] == 'y') { std::ifstream is(p.path().c_str()); - strict_json_parsing err_handler; - json_stream_reader reader(is, err_handler); + auto options = json_options{}.err_handler(strict_json_parsing{}); + json_stream_reader reader(is, options); std::error_code ec; reader.read(ec); if (ec) @@ -53,8 +53,8 @@ TEST_CASE("JSON Parsing Test Suite") if (fs::exists(p) && fs::is_regular_file(p) && p.path().extension() == ".json" && p.path().filename().c_str()[0] == 'n') { std::ifstream is(p.path().c_str()); - strict_json_parsing err_handler; - json_stream_reader reader(is, err_handler); + auto options = json_options{}.err_handler(strict_json_parsing{}); + json_stream_reader reader(is, options); std::error_code ec; reader.read(ec); if (!ec) diff --git a/test/fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_cbor_encoder-4729089884225536 b/test/fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_cbor_encoder-4729089884225536 new file mode 100644 index 0000000000000000000000000000000000000000..91d5daab00bbef0a258b6240144833ab0df69874 GIT binary patch literal 12 OcmX@wB;CLO0SW*Vi~<7y literal 0 HcmV?d00001 diff --git a/test/fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_ubjson_encoder-6542820946542592 b/test/fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_ubjson_encoder-6542820946542592 new file mode 100644 index 0000000000000000000000000000000000000000..85204a3e55599c1f0caa50346e0ff057acf35a57 GIT binary patch literal 43968 zcmeI*+ilx06vlCO7Wcgf&}0Om3+N@9pg=d!GMy!pmAcUsMFvT$*a-TwAABU=q|fK_ zKcp-T&p*TSF!UkbTet3b8-}ml<=2-GLNdB8zW+z%Gsd`XjQ22%mp)97Z~wf?$IWj} z>p#zSr%mpUyWi1s5v8TWRlJIInx1u^Zhd1~|9|`7nQ`6v`EQg~eEl7BI`N5rC!FAV zT#xImKz~b)7kC0s;0e4qjv(#aYVbtTm2@RtNmtUn;fS@QE9pwQlCGpH>6*<*Q)jF3 z0aL^Zu7a!JD!2-+f~(*vxVZvwgqkP)%NS?_ZJ-Ubfi}+lcmYhWNETA zS(>a|fmYX4)(cjmyDSDcA?V)-+qa+(I8V^YEBQ_G(uG{4N8N zXYRmz22?|c=b#z;jD6OtNFT&oy!^VI*$W;Y)`iE1rLMpEv8BFjIYv(2l&GCUPrQhi z buf; - cbor::cbor_bytes_encoder encoder(buf); - cbor::cbor_stream_reader reader(is, encoder); - - std::error_code ec; - REQUIRE_NOTHROW(reader.read(ec)); - CHECK(ec == cbor::cbor_errc::illegal_chunked_string); //-V521 - } - catch (const std::exception& e) - { - std::cout << e.what() << "" << std::endl; - } - } - // Fuzz target: fuzz_csv_encoder // Issue: Failed throw // Resolution: check if csv_parser is still in start state when no more input @@ -507,24 +482,6 @@ TEST_CASE("oss-fuzz issues") reader.read(ec); } - // Fuzz target: fuzz_ubjson_encoder - // Issue: Timeout - SECTION("issue 23840") - { - std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_ubjson_encoder-5711604342849536"; - - std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary); - CHECK(is); //-V521 - - std::vector output; - ubjson::ubjson_bytes_encoder encoder(output); - ubjson::ubjson_stream_reader reader(is, encoder); - - std::error_code ec; - reader.read(ec); - CHECK(ec == ubjson::ubjson_errc::unknown_type); //-V521 - } - // Fuzz target: fuzz_ubjson // Issue: failed_throw SECTION("issue 25891") @@ -704,4 +661,95 @@ TEST_CASE("oss-fuzz issues") } } } +#endif + +TEST_CASE("Fuzz target: fuzz_ubjson_encoder") +{ + // Issue: Timeout + /*SECTION("issue 23840") + { + std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_ubjson_encoder-5711604342849536"; + std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary); + CHECK(is); //-V521 + + std::vector output; + ubjson::ubjson_bytes_encoder encoder(output); + ubjson::ubjson_stream_reader reader(is, encoder); + + std::error_code ec; + reader.read(ec); + CHECK(ec == ubjson::ubjson_errc::unknown_type); //-V521 + }*/ + + // Issue: Timeout (exceeds 60 secs) + /*SECTION("issue 378891965") + { + std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_ubjson_encoder-6542820946542592"; + + std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary); + CHECK(is); //-V521 + + std::vector output; + ubjson::ubjson_bytes_encoder encoder(output); + ubjson::ubjson_stream_reader reader(is, encoder); + + std::error_code ec; + reader.read(ec); + CHECK(ec == ubjson::ubjson_errc::unknown_type); //-V521 + }*/ +} + +TEST_CASE("Fuzz target: fuzz_cbor_encoder") +{ + // Fuzz target: fuzz_cbor_encoder + // Issue: failed_throw + // Resolution: change assert to illegal_chunked_string error code +/* SECTION("issue 21902") + { + std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-fuzz_cbor_encoder-5665976638242816"; + + std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary); + CHECK(is); //-V521 + + try + { + std::vector buf; + cbor::cbor_bytes_encoder encoder(buf); + cbor::cbor_stream_reader reader(is, encoder); + + std::error_code ec; + REQUIRE_NOTHROW(reader.read(ec)); + CHECK(ec == cbor::cbor_errc::illegal_chunked_string); //-V521 + } + catch (const std::exception& e) + { + std::cout << e.what() << "" << std::endl; + } + } +*/ + // Fuzz target: fuzz_cbor_encoder + // Issue: Integer-overflow + SECTION("issue 42538003") + { + std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_cbor_encoder-4729089884225536"; + + std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary); + CHECK(is); //-V521 + + try + { + std::vector buf; + cbor::cbor_bytes_encoder encoder(buf); + cbor::cbor_stream_reader reader(is, encoder); + + std::error_code ec; + REQUIRE_NOTHROW(reader.read(ec)); + CHECK(ec == cbor::cbor_errc::illegal_chunked_string); //-V521 + } + catch (const std::exception& e) + { + std::cout << e.what() << "" << std::endl; + } + } +}