Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clusterfuzzlite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM gcr.io/oss-fuzz-base/base-builder-go
COPY . $SRC/
WORKDIR colly
COPY .clusterfuzzlite/build.sh $SRC/
6 changes: 6 additions & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -eu

go get github.com/AdamKorcz/go-118-fuzz-build/utils
go get github.com/AdamKorcz/go-fuzz-headers
compile_native_go_fuzzer github.com/gocolly/colly/v2 FuzzHtmlElementUnmarshal FuzzHtmlElementUnmarshal

1 change: 1 addition & 0 deletions .clusterfuzzlite/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: go
29 changes: 29 additions & 0 deletions .github/workflows/cflite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ClusterFuzzLite PR fuzzing
on:
workflow_dispatch:
pull_request:
paths:
- '**'
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: go
- name: Run Fuzzers (${{ matrix.sanitizer }})
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fuzz-seconds: 400
mode: 'code-change'
sanitizer: ${{ matrix.sanitizer }}
39 changes: 39 additions & 0 deletions unmarshal_fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package colly

import (
"bytes"
"testing"

fuzz "github.com/AdamKorcz/go-fuzz-headers"
"github.com/PuerkitoBio/goquery"
)

type info struct {
Text string `selector:"span"`
}

type object struct {
Info []*info `selector:"li.info"`
}

func FuzzHtmlElementUnmarshal(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
gfh := fuzz.NewConsumer(data)
e := &HTMLElement{}
err := gfh.GenerateStruct(e)
if err != nil {
return
}
d2, err := gfh.GetBytes()
if err != nil {
return
}
doc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(d2))
if err != nil {
return
}
e.DOM = doc.First()
o := object{}
e.Unmarshal(&o)
})
}