Wee fuzz test and associated bug fixes
This commit is contained in:
51
src/fuzz.cpp
Normal file
51
src/fuzz.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "minify.h"
|
||||
#include "parser3.h"
|
||||
|
||||
void testStreaming(std::string const &json) {
|
||||
MinifyState streaming;
|
||||
MinifyState batch;
|
||||
auto c = minifyCallbacks();
|
||||
parser3::Status streamingStatus = parser3::S_OK;
|
||||
parser3::Status batchStatus = parser3::S_OK;
|
||||
do {
|
||||
auto copy = json;
|
||||
parser3::Parser3 parser(&c, &streaming);
|
||||
for (int i = 0; i < copy.size(); ++i) {
|
||||
auto s = parser.parse(copy.data() + i, 1);
|
||||
if (s != parser3::S_AGAIN) {
|
||||
streamingStatus = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto s = parser.parse(nullptr, 0);
|
||||
if (s != parser3::S_OK) {
|
||||
streamingStatus = s;
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
do {
|
||||
auto copy = json;
|
||||
parser3::Parser3 parser(&c, &batch);
|
||||
auto s = parser.parse(copy.data(), copy.size());
|
||||
if (s != parser3::S_AGAIN) {
|
||||
batchStatus = s;
|
||||
break;
|
||||
}
|
||||
s = parser.parse(nullptr, 0);
|
||||
if (s != parser3::S_OK) {
|
||||
batchStatus = s;
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
if (streamingStatus != batchStatus) {
|
||||
abort();
|
||||
}
|
||||
if (streaming.result != batch.result) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
testStreaming(std::string((const char *)data, size));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user