3 Commits
Author SHA1 Message Date
andrew 46408fd56f Add a fallback fuzz binary if libfuzzer not available 2026-06-14 23:30:42 -04:00
andrew 063872ed3c Fix potential stack overflow for no musttail
Closes #1
2026-06-14 23:29:31 -04:00
andrew b76f47abf7 Set cmake_minimum_required to 3.10 2026-06-14 22:43:12 -04:00
4 changed files with 46 additions and 1 deletions
+6 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.10)
project( project(
weaseljson weaseljson
VERSION 0.0.1 VERSION 0.0.1
@@ -173,6 +173,11 @@ if(HAS_LIB_FUZZER)
target_link_libraries(fuzz PRIVATE simdjson) target_link_libraries(fuzz PRIVATE simdjson)
target_compile_options(fuzz PRIVATE -fsanitize=fuzzer ${TEST_FLAGS}) target_compile_options(fuzz PRIVATE -fsanitize=fuzzer ${TEST_FLAGS})
target_link_options(fuzz PRIVATE -fsanitize=fuzzer) target_link_options(fuzz PRIVATE -fsanitize=fuzzer)
else()
add_executable(fuzz src/fuzz.cpp src/lib.cpp src/fuzz_driver.cpp)
target_include_directories(fuzz PRIVATE include)
target_link_libraries(fuzz PRIVATE simdjson)
target_compile_options(fuzz PRIVATE ${TEST_FLAGS})
endif() endif()
add_executable(validate src/validate.cpp) add_executable(validate src/validate.cpp)
+19
View File
@@ -0,0 +1,19 @@
#include <cstddef>
#include <cstdint>
#include <fstream>
#include <sstream>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
int main(int argc, char **argv) {
auto doTest = [&]() {
for (int i = 1; i < argc; ++i) {
std::ifstream t(argv[i], std::ios::binary);
std::stringstream buffer;
buffer << t.rdbuf();
auto str = buffer.str();
LLVMFuzzerTestOneInput((const uint8_t *)str.data(), str.size());
}
};
doTest();
}
+1
View File
@@ -6,6 +6,7 @@
#if __has_attribute(musttail) #if __has_attribute(musttail)
#define MUSTTAIL __attribute__((musttail)) #define MUSTTAIL __attribute__((musttail))
#define HAS_MUSTTAIL
#else #else
#define MUSTTAIL #define MUSTTAIL
#endif #endif
+20
View File
@@ -146,6 +146,10 @@ struct Parser3 {
NumDfa numDfa; NumDfa numDfa;
Utf8Dfa strDfa; Utf8Dfa strDfa;
bool inKey = false; bool inKey = false;
#ifndef HAS_MUSTTAIL
char *stashBufForTrampoline;
#endif
}; };
inline PRESERVE_NONE WeaselJsonStatus skipWhitespace(char *&buf, char *bufEnd) { inline PRESERVE_NONE WeaselJsonStatus skipWhitespace(char *&buf, char *bufEnd) {
@@ -1029,13 +1033,29 @@ constexpr inline struct ContinuationTable {
inline WeaselJsonStatus Parser3::parse(char *buf, int len) { inline WeaselJsonStatus Parser3::parse(char *buf, int len) {
this->dataBegin = this->writeBuf = buf; this->dataBegin = this->writeBuf = buf;
#ifdef HAS_MUSTTAIL
return symbolTables.continuations[top()](this, buf, buf + len); return symbolTables.continuations[top()](this, buf, buf + len);
#else
this->stashBufForTrampoline = buf;
WeaselJsonStatus result;
while ((result = symbolTables.continuations[top()](
this, stashBufForTrampoline, buf + len)) == WeaselJsonStatus(-1))
;
return result;
#endif
} }
inline PRESERVE_NONE WeaselJsonStatus Parser3::keepGoing(Parser3 *self, inline PRESERVE_NONE WeaselJsonStatus Parser3::keepGoing(Parser3 *self,
char *buf, char *buf,
char *bufEnd) { char *bufEnd) {
#ifdef HAS_MUSTTAIL
MUSTTAIL return symbolTables.continuations[self->top()](self, buf, bufEnd); MUSTTAIL return symbolTables.continuations[self->top()](self, buf, bufEnd);
#else
self->stashBufForTrampoline = buf;
(void)bufEnd;
return WeaselJsonStatus(-1);
#endif
} }
} // namespace parser3 } // namespace parser3