diff --git a/.github/workflows/mayhem.yml b/.github/workflows/mayhem.yml new file mode 100644 index 00000000..65ae96e0 --- /dev/null +++ b/.github/workflows/mayhem.yml @@ -0,0 +1,61 @@ +name: Mayhem +on: + push: + pull_request: + workflow_dispatch: + workflow_call: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + name: ${{ matrix.os }} shared=${{ matrix.shared }} ${{ matrix.build_type }} + runs-on: ${{ matrix.os }} + permissions: + packages: write + contents: write + security-events: write + + strategy: + matrix: + os: [ubuntu-latest] + shared: [false] + build_type: [Release] + include: + - os: ubuntu-latest + triplet: x64-linux + + steps: + - uses: actions/checkout@v6.0.2 + + - 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: Set up Docker Buildx + uses: docker/setup-buildx-action@v4.0.0 + + - name: Build and push Docker image + uses: docker/build-push-action@v7.1.0 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Start analysis + uses: forallsecure/mcode-action@long-runs + with: + mayhem-token: ${{ secrets.MAYHEM_TOKEN }} + args: --image ${{ steps.meta.outputs.tags }} --duration 300 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c1594017 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.11-slim + +RUN apt-get update && apt-get install -y clang && rm -rf /var/lib/apt/lists/* +RUN pip3 install atheris + +COPY . /html5lib +WORKDIR /html5lib +RUN python3 -m pip install -r requirements.txt +RUN python3 -m pip install . && chmod +x fuzz/fuzz_html_parser.py diff --git a/Mayhemfile b/Mayhemfile new file mode 100644 index 00000000..d0ea9290 --- /dev/null +++ b/Mayhemfile @@ -0,0 +1,6 @@ +project: html5lib-python +target: fuzz_html_parser + +cmds: + - cmd: fuzz/fuzz_html_parser.py + libfuzzer: true diff --git a/fuzz/fuzz_html_parser.py b/fuzz/fuzz_html_parser.py new file mode 100644 index 00000000..8c51ecdd --- /dev/null +++ b/fuzz/fuzz_html_parser.py @@ -0,0 +1,17 @@ +#!/usr/local/bin/python3 +import atheris +import sys + +with atheris.instrument_imports(): + import html5lib + + +@atheris.instrument_func +def TestOneInput(data): + fdp = atheris.FuzzedDataProvider(data) + html5lib.parse(fdp.ConsumeString(len(data))) + + +# atheris.instrument_all() +atheris.Setup(sys.argv, TestOneInput) +atheris.Fuzz() \ No newline at end of file