Skip to content

fuzzing: add cjson_print_roundtrip_fuzzer for print/serialize paths#1029

Open
XananasX7 wants to merge 1 commit into
DaveGamble:masterfrom
XananasX7:add-print-roundtrip-fuzzer
Open

fuzzing: add cjson_print_roundtrip_fuzzer for print/serialize paths#1029
XananasX7 wants to merge 1 commit into
DaveGamble:masterfrom
XananasX7:add-print-roundtrip-fuzzer

Conversation

@XananasX7
Copy link
Copy Markdown

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.c

Coverage added:

  • cJSON_ParseWithLength() — parse with explicit length (catches boundary bugs)
  • cJSON_PrintUnformatted() — compact serialization of parsed trees
  • cJSON_Print() — formatted serialization
  • cJSON_PrintBuffered() with 16-byte prebuf — forces internal buffer reallocation
  • cJSON_Duplicate() — deep copy exercises recursive tree traversal
  • Round-trip: parse → print → re-parse (verifies serializer output is valid JSON)

Why this matters

The existing cjson_read_fuzzer only calls cJSON_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 into cJSON_Print() could trigger integer overflows in buffer size calculations.

Build

Integrates with the existing fuzzing/ossfuzz.sh — one new $CC line added.

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.
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.

1 participant