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,10 +25,7 @@ std::pair<std::string, WeaselJsonStatus> runStreaming(std::string copy,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto s = parser.parse(nullptr, 0);
|
auto s = parser.parse(nullptr, 0);
|
||||||
if (s != WeaselJson_OK) {
|
|
||||||
return {state.result, s};
|
return {state.result, s};
|
||||||
}
|
|
||||||
return {state.result, WeaselJson_OK};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string, WeaselJsonStatus> runBatch(std::string copy) {
|
std::pair<std::string, WeaselJsonStatus> runBatch(std::string copy) {
|
||||||
@@ -40,27 +37,31 @@ std::pair<std::string, WeaselJsonStatus> runBatch(std::string copy) {
|
|||||||
return {state.result, s};
|
return {state.result, s};
|
||||||
}
|
}
|
||||||
s = parser.parse(nullptr, 0);
|
s = parser.parse(nullptr, 0);
|
||||||
if (s != WeaselJson_OK) {
|
|
||||||
return {state.result, s};
|
return {state.result, s};
|
||||||
}
|
|
||||||
return {state.result, WeaselJson_OK};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testStreaming(std::string const &json) {
|
void testStreaming(std::string const &json) {
|
||||||
auto batch = runBatch(json);
|
auto batch = runBatch(json);
|
||||||
|
if (batch.second == WeaselJson_AGAIN) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
for (int stride = 1; stride < 16; ++stride) {
|
for (int stride = 1; stride < 16; ++stride) {
|
||||||
auto streaming = runStreaming(json, stride);
|
auto streaming = runStreaming(json, stride);
|
||||||
if (streaming != batch) {
|
if (streaming != batch) {
|
||||||
if (streaming.second == batch.second &&
|
if (streaming.second == WeaselJson_AGAIN) {
|
||||||
streaming.second != WeaselJson_OK) {
|
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
|
// It's ok if the processed data doesn't match if parsing failed
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
printf("streaming: %s, %s\n",
|
printf("streaming: %s, %s\n",
|
||||||
streaming.second == WeaselJson_OK ? "accept" : "reject",
|
streaming.second == WeaselJson_OK ? "accept" : "reject",
|
||||||
streaming.first.c_str());
|
streaming.first.c_str());
|
||||||
printf("batch: %s, %s\n",
|
printf("batch: %s, %s\n",
|
||||||
streaming.second == WeaselJson_OK ? "accept" : "reject",
|
batch.second == WeaselJson_OK ? "accept" : "reject",
|
||||||
batch.first.c_str());
|
batch.first.c_str());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user