diff --git a/.github/workflows/mayhem.yml b/.github/workflows/mayhem.yml new file mode 100644 index 0000000..6b185ad --- /dev/null +++ b/.github/workflows/mayhem.yml @@ -0,0 +1,72 @@ +name: Mayhem +on: + push: + pull_request: + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + name: '${{ matrix.os }} shared=${{ matrix.shared }} ${{ matrix.build_type }}' + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + shared: [false] + build_type: [Release] + include: + - os: ubuntu-latest + triplet: x64-linux + + steps: + - uses: actions/checkout@v6.0.2 + with: + submodules: recursive + + - name: Log in to the Container registry + uses: docker/login-action@v4.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v6.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v7.1.0 + with: + context: . + push: true + file: mayhem/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + outputs: + image: ${{ steps.meta.outputs.tags }} + + mayhem: + needs: build + name: 'fuzz ${{ matrix.mayhemfile }}' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + mayhemfile: + - mayhem/Mayhemfile + + steps: + - uses: actions/checkout@v6.0.2 + + - name: Start analysis for ${{ matrix.mayhemfile }} + uses: forallsecure/mcode-action@long-runs + with: + mayhem-token: ${{ secrets.MAYHEM_TOKEN }} + args: --image ${{ needs.build.outputs.image }} --file ${{ matrix.mayhemfile }} --duration 600 + diff --git a/mayhem/Dockerfile b/mayhem/Dockerfile new file mode 100644 index 0000000..bd33a24 --- /dev/null +++ b/mayhem/Dockerfile @@ -0,0 +1,12 @@ +FROM fuzzers/atheris:2.0.7-python3.9 + +RUN apt-get update + +ADD . /src +WORKDIR /src + +RUN python3 -m pip install --upgrade pip +RUN python3 -m pip install codext +RUN chmod +x /src/mayhem/fuzz-codext.py + +CMD ["/src/mayhem/fuzz-codext.py"] diff --git a/mayhem/Mayhemfile b/mayhem/Mayhemfile new file mode 100644 index 0000000..d5140ff --- /dev/null +++ b/mayhem/Mayhemfile @@ -0,0 +1,6 @@ +project: python-codext +target: fuzz-codext + +cmds: + - cmd: /src/mayhem/fuzz-codext.py + libfuzzer: true diff --git a/mayhem/fuzz-codext.py b/mayhem/fuzz-codext.py new file mode 100755 index 0000000..58d97c0 --- /dev/null +++ b/mayhem/fuzz-codext.py @@ -0,0 +1,26 @@ +#! /usr/bin/python3 + +import atheris +import sys +import io +import random + +with atheris.instrument_imports(): + import codext + +def TestOneInput(input_bytes): + try: + fdp = atheris.FuzzedDataProvider(input_bytes) + data = fdp.ConsumeString(sys.maxsize) + encoded = codext.encode(data, "base100") + except UnicodeDecodeError: + pass + except ValueError: + pass + +def main(): + atheris.Setup(sys.argv, TestOneInput) + atheris.Fuzz() + +if __name__ == "__main__": + main()