Pass test if one parser says overflow and the other says reject
Maybe in the future we could rerun with a bigger stack?
This commit is contained in:
21
src/fuzz.cpp
21
src/fuzz.cpp
@@ -25,11 +25,8 @@ std::pair<std::string, WeaselJsonStatus> runStreaming(std::string copy,
|
||||
}
|
||||
}
|
||||
auto s = parser.parse(nullptr, 0);
|
||||
if (s != WeaselJson_OK) {
|
||||
return {state.result, s};
|
||||
}
|
||||
return {state.result, WeaselJson_OK};
|
||||
}
|
||||
|
||||
std::pair<std::string, WeaselJsonStatus> runBatch(std::string copy) {
|
||||
SerializeState state;
|
||||
@@ -40,27 +37,31 @@ std::pair<std::string, WeaselJsonStatus> 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};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user