diff --git a/.clusterfuzzlite/Dockerfile b/.clusterfuzzlite/Dockerfile new file mode 100644 index 0000000..f1c3a81 --- /dev/null +++ b/.clusterfuzzlite/Dockerfile @@ -0,0 +1,6 @@ +FROM gcr.io/oss-fuzz-base/base-builder +RUN apt-get update && apt-get install -y make autoconf automake libtool + +COPY . $SRC/csv2 +COPY .clusterfuzzlite/build.sh $SRC/build.sh +WORKDIR $SRC/csv2 diff --git a/.clusterfuzzlite/README.md b/.clusterfuzzlite/README.md new file mode 100644 index 0000000..6461d7a --- /dev/null +++ b/.clusterfuzzlite/README.md @@ -0,0 +1,4 @@ +# ClusterFuzzLite set up + +This folder contains a fuzzing set for [ClusterFuzzLite](https://google.github.io/clusterfuzzlite). + \ No newline at end of file diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh new file mode 100644 index 0000000..188eb60 --- /dev/null +++ b/.clusterfuzzlite/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash -eu + +# Copy all fuzzer executables to $OUT/ +$CXX $CFLAGS $LIB_FUZZING_ENGINE \ + $SRC/csv2/.clusterfuzzlite/reader_fuzzer.cpp \ + -o $OUT/reader_fuzzer \ + -I$SRC/csv2/include diff --git a/.clusterfuzzlite/project.yaml b/.clusterfuzzlite/project.yaml new file mode 100644 index 0000000..b478801 --- /dev/null +++ b/.clusterfuzzlite/project.yaml @@ -0,0 +1 @@ +language: c++ diff --git a/.clusterfuzzlite/reader_fuzzer.cpp b/.clusterfuzzlite/reader_fuzzer.cpp new file mode 100644 index 0000000..6ad0146 --- /dev/null +++ b/.clusterfuzzlite/reader_fuzzer.cpp @@ -0,0 +1,29 @@ +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + std::string fuzz_payload(reinterpret_cast(data), size); + + csv2::Reader, csv2::quote_character<'"'>, csv2::first_row_is_header, + csv2::trim_policy::trim_whitespace> + csv; + bool cont = false; + + try { + csv.parse(fuzz_payload); + cont = true; + } catch (...) { + } + + if (cont) { + const auto header = csv.header(); + for (const auto row : csv) { + for (const auto cell : row) { + std::string value; + cell.read_value(value); + } + } + } + + return 0; +} \ No newline at end of file diff --git a/.github/workflows/cflite_pr.yml b/.github/workflows/cflite_pr.yml new file mode 100644 index 0000000..a6ddd01 --- /dev/null +++ b/.github/workflows/cflite_pr.yml @@ -0,0 +1,30 @@ +name: ClusterFuzzLite PR fuzzing +on: + workflow_dispatch: + pull_request: + branches: [ master ] +permissions: read-all +jobs: + PR: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + sanitizer: [address] + steps: + - name: Build Fuzzers (${{ matrix.sanitizer }}) + id: build + uses: google/clusterfuzzlite/actions/build_fuzzers@v1 + with: + sanitizer: ${{ matrix.sanitizer }} + language: c++ + bad-build-check: false + - name: Run Fuzzers (${{ matrix.sanitizer }}) + id: run + uses: google/clusterfuzzlite/actions/run_fuzzers@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fuzz-seconds: 100 + mode: 'code-change' + report-unreproducible-crashes: false + sanitizer: ${{ matrix.sanitizer }}