From d68c9a8ccc73a1620c0d179639a1e58557928716 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 22 May 2025 12:57:12 -0400 Subject: [PATCH] Pass test if one parser says overflow and the other says reject Maybe in the future we could rerun with a bigger stack? --- src/fuzz.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/fuzz.cpp b/src/fuzz.cpp index 78b045c..82da5e9 100644 --- a/src/fuzz.cpp +++ b/src/fuzz.cpp @@ -25,10 +25,7 @@ std::pair runStreaming(std::string copy, } } auto s = parser.parse(nullptr, 0); - if (s != WeaselJson_OK) { - return {state.result, s}; - } - return {state.result, WeaselJson_OK}; + return {state.result, s}; } std::pair runBatch(std::string copy) { @@ -40,27 +37,31 @@ std::pair runBatch(std::string copy) { return {state.result, s}; } s = parser.parse(nullptr, 0); - if (s != WeaselJson_OK) { - return {state.result, s}; - } - return {state.result, WeaselJson_OK}; + return {state.result, s}; } void testStreaming(std::string const &json) { auto batch = runBatch(json); + if (batch.second == WeaselJson_AGAIN) { + abort(); + } for (int stride = 1; stride < 16; ++stride) { auto streaming = runStreaming(json, stride); if (streaming != batch) { - if (streaming.second == batch.second && - streaming.second != WeaselJson_OK) { + if (streaming.second == WeaselJson_AGAIN) { + abort(); + } + bool streamingOk = streaming.second == WeaselJson_OK; + bool batchOk = batch.second == WeaselJson_OK; + if (streamingOk == batchOk && !batchOk) { // It's ok if the processed data doesn't match if parsing failed - return; + continue; } printf("streaming: %s, %s\n", streaming.second == WeaselJson_OK ? "accept" : "reject", streaming.first.c_str()); printf("batch: %s, %s\n", - streaming.second == WeaselJson_OK ? "accept" : "reject", + batch.second == WeaselJson_OK ? "accept" : "reject", batch.first.c_str()); abort(); }