fix jq_fuzz_parse_stream: use iterative parser API for streaming mode (#3499)

This commit is contained in:
Ze Sheng authored and GitHub committed 2026-03-11 11:49:14 +09:00
1 parent 1a394919f9
commit b6a9e260cd
1 file changed
+17 -5
+17 -5
View File
@@ -5,15 +5,27 @@
#include "jv.h"
int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
// Creat null-terminated string
// Create null-terminated string
char *null_terminated = (char *)malloc(size + 1);
memcpy(null_terminated, (char *)data, size);
null_terminated[size] = '\0';
// Fuzzer entrypoint
jv res = jv_parse_custom_flags(null_terminated, JV_PARSE_STREAMING);
jv_free(res);
// Use the iterative jv_parser API for streaming mode.
// The single-shot jv_parse_custom_flags() returns "Unexpected extra JSON
// values" for any compound JSON in streaming mode, because the streaming
// parser produces multiple tokens but the single-shot API expects exactly
// one value.
jv_parser *parser = jv_parser_new(JV_PARSE_STREAMING);
jv_parser_set_buf(parser, null_terminated, (int)size, 0);
jv value;
while (jv_is_valid(value = jv_parser_next(parser))) {
jv_free(value);
}
jv_free(value);
jv_parser_free(parser);
// Free the null-terminated string
free(null_terminated);