Skip to content

OSS-Fuzz: Move fuzzer to upstream repository - #1724

Open
arthurscchan wants to merge 5 commits into
open-source-parsers:masterfrom
arthurscchan:oss-fuzz-fuzzers-upstream
Open

arthurscchan wants to merge 5 commits into
open-source-parsers:masterfrom
arthurscchan:oss-fuzz-fuzzers-upstream

Conversation

@arthurscchan

Copy link
Copy Markdown

This PR moves all the OSS-Fuzz fuzzers to the upstream storage for easier management. This PR works together with OSS-Fuzz (google/oss-fuzz#16308) to accommodate the moving of fuzzers upstream.

Of course, this is only a suggestion. If the maintainers would prefer the fuzzers to remain in OSS-Fuzz, I am happy to keep the current setup and to ping the relevant maintainers for review whenever I add new fuzzers later in the process.

Thank you for considering this, and I would welcome any feedback on the preferred approach.

Remark: After this PR is accepted and merged, there will be additional PRs for adding new fuzzers for this project later.

Signed-off-by: Arthur SC Chan <arthur.chan@adalogics.com>
@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The changes reach only opt-in fuzzing and OSS-Fuzz build workflows.

Fix the object-only library selection before merging.

Findings

  1. P1 Object-only fuzz build fails ▶

Summary

Adds upstream sources for the protobuf-based fuzzer and an optional standalone jsoncpp_fuzzer target.

  • Fuzz builds can create the raw-input fuzzer without building unit tests.
  • Structured protobuf inputs can now exercise JsonCpp's parser.

Reviews (5) · Last reviewed commit: "Merge branch 'master' into oss-fuzz-fuzz..." · Reviewed by Greptile

Comment thread src/test_lib_json/CMakeLists.txt Outdated
Comment thread src/test_lib_json/CMakeLists.txt Outdated
Comment thread src/test_lib_json/jsoncpp_fuzz_proto.cc Outdated
Comment thread src/test_lib_json/json_proto_converter.cc Outdated
Comment thread src/test_lib_json/json_proto_converter.cc Outdated
Signed-off-by: Arthur SC Chan <arthur.chan@adalogics.com>
Comment thread src/test_lib_json/json_proto_converter.cc
Signed-off-by: Arthur SC Chan <arthur.chan@adalogics.com>
Comment thread src/test_lib_json/json_proto_converter.cc Outdated
Signed-off-by: Arthur SC Chan <arthur.chan@adalogics.com>
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 39566034341

Coverage remained the same at 89.907%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 2740
Covered Lines: 2615
Line Coverage: 95.44%
Relevant Branches: 2640
Covered Branches: 2222
Branch Coverage: 84.17%
Branches in Coverage %: Yes
Coverage Strength: 23828.01 hits per line

💛 - Coveralls

@baylesj baylesj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the automatic greptile feedback. I did a more extensive review and have some asks before landing this in JsonCpp.

@@ -0,0 +1,158 @@
// Copyright 2020 Google Inc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not morally opposed to landing this PR, however introducing Apache licensed code has some licensing headaches that I would prefer to avoid. Can you relicense this as a new file matching JsonCpp's existing licensing? it is allowed under Google policy AFAIK.

# sources are kept here so they live with the other jsoncpp fuzzers.
set(JSONCPP_FUZZ_ENGINE "" CACHE STRING
"Fuzzing engine link flags for jsoncpp_fuzzer, e.g. -fsanitize=fuzzer")
if(JSONCPP_WITH_FUZZING)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing builds this target yet, since the OSS-Fuzz build.sh still compiles fuzz.cpp directly. Also, with this ON and JSONCPP_FUZZ_ENGINE empty, linking fails because fuzz.cpp has no main. Could we error out at configure time here (or require the engine flags)?

# main() is not pulled into compiler checks and other executables.
#
# The libprotobuf-mutator based fuzzer (jsoncpp_fuzz_proto.cc, json.proto,
# json_proto_converter.*) is built by OSS-Fuzz separately with LPM; the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the sources live here, I'd want CI to build them; otherwise they'll only break in OSS-Fuzz. A CIFuzz workflow would cover both fuzzers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can probably handle this as a follow up if needed.

required JsonObject object_value = 2;
}

message JsonObject {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since JsonObject has exactly one name/value, generated objects never have more than one member, so rejectDupKeys can never trigger and object-member handling barely gets exercised. JsonObject.settings is also unused.


#include "json_proto_converter.h"

#include <charconv>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Floating-point std::to_chars needs C++17 and a fairly recent standard library (libc++ 14+, libstdc++ 11+). The library itself is C++11, and this only builds in OSS-Fuzz because build.sh seds the standard to 17.

if (number_value.has_float_value()) {
const double value = number_value.float_value().value();
// Keep "inf"/"nan" out of the output; they are not valid JSON numbers.
data_ << (std::isfinite(value) ? value : 0.0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still writes doubles at the stream's default precision of 6 significant digits, which is the same digit loss that was fixed for exponent_frac_value above.

Json::Value root;
try {
reader->parse(begin, end, &root, nullptr);
} catch (Json::Exception const&) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: fuzz.cpp wraps this in #if JSON_USE_EXCEPTION so it builds with exceptions disabled. Also, the Json::Exception forward declaration and the duplicate or unused includes above can go.


} // namespace json_proto

#endif // TESTING_LIBFUZZER_PROTO_JSON_PROTO_CONVERTER_H_

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the comment doesn't match the guard name (JSON_PROTO_CONVERTER_H_).

Comment on lines +65 to +68
if(BUILD_SHARED_LIBS)
target_link_libraries(jsoncpp_fuzzer jsoncpp_lib)
else()
target_link_libraries(jsoncpp_fuzzer jsoncpp_static)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Object-only fuzz build fails

With BUILD_SHARED_LIBS=OFF, BUILD_STATIC_LIBS=OFF, BUILD_OBJECT_LIBS=ON, and tests disabled, enabling JSONCPP_WITH_FUZZING selects jsoncpp_static, which is never created. The fuzz target then fails to link even when a fuzzing engine is supplied. Select jsoncpp_object when only the object library is enabled.

Knowledge Base Used: CMake, Meson, and Bazel integration

@arthurscchan

Copy link
Copy Markdown
Author

Thanks for the comments. Please spare me a few days to address those comments as I am stucked in some other things now. I will address them asap. Sorry for the delay.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants