fuzzing: add cjson_print_roundtrip_fuzzer for print/serialize paths#1029
Open
XananasX7 wants to merge 1 commit into
Open
fuzzing: add cjson_print_roundtrip_fuzzer for print/serialize paths#1029XananasX7 wants to merge 1 commit into
XananasX7 wants to merge 1 commit into
Conversation
Add a new libFuzzer harness that exercises cJSON's print/serialization code paths, which are not covered by the existing cjson_read_fuzzer: - cJSON_ParseWithLength(): parse with explicit length (catches off-by-one) - cJSON_PrintUnformatted(): serialize parsed trees to compact JSON - cJSON_Print(): formatted serialization - cJSON_PrintBuffered(): buffered print with small prebuf forces realloc - cJSON_Duplicate(): deep copy of parsed trees - Round-trip consistency: parse -> print -> re-parse These paths manipulate heap-allocated string buffers and are reachable whenever a caller serializes a parsed or programmatically built cJSON tree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new libFuzzer harness for cJSON's serialization (print) code paths, which are currently unexercised by OSS-Fuzz.
New harness:
fuzzing/cjson_print_roundtrip_fuzzer.cCoverage added:
cJSON_ParseWithLength()— parse with explicit length (catches boundary bugs)cJSON_PrintUnformatted()— compact serialization of parsed treescJSON_Print()— formatted serializationcJSON_PrintBuffered()with 16-byte prebuf — forces internal buffer reallocationcJSON_Duplicate()— deep copy exercises recursive tree traversalWhy this matters
The existing
cjson_read_fuzzeronly callscJSON_Parse(). The print/serialize code paths allocate and grow heap buffers dynamically and are reachable whenever a caller serializes a cJSON tree. A parse-triggered deep/wide tree fed intocJSON_Print()could trigger integer overflows in buffer size calculations.Build
Integrates with the existing
fuzzing/ossfuzz.sh— one new$CCline added.