From 4039583ccd9260aa58759bfa2a0883f684601428 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Thu, 13 Jun 2019 11:11:47 -0500 Subject: [PATCH 1/7] Added fuzzing code and readme.md to explain --- roaring/README.md | 30 ++++++++++++++++++++++++++++++ roaring/fuzzer.go | 12 ++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 roaring/README.md create mode 100644 roaring/fuzzer.go diff --git a/roaring/README.md b/roaring/README.md new file mode 100644 index 000000000..3599a6813 --- /dev/null +++ b/roaring/README.md @@ -0,0 +1,30 @@ +# The Fuzzer + +For complete documentation on go-fuzz, please see: https://github.com/dvyukov/go-fuzz + +The fuzzer in relation to the roaring package checks the `Bitmap.UnmarshalBinary` function found in `roaring.go`. In order to use the fuzzer, you can follow these steps: + +`cd $GOPATH/src/github.com/pilosa/pilosa/roaring` + +`go-fuzz-build ./` + +You must now make the workdir/corpus directory. This is achieved by: + +`mkdir workdir/corpus` + +The fuzzer needs some input to start the fuzzing with. Copy some sample fragments into the workdir/corpus folder. Once you have copied your sample inputs, you are ready to run the fuzzer: + +`go-fuzz` + +## Understanding the Fuzzer Output + +The fuzzer will output something similar to the follwoing: + +`2015/04/25 12:39:53 workers: 8, corpus: 124 (12s ago), crashers: 37, restarts: 1/15, execs: 35342 (2941/sec), cover: 403, uptime: 12s` + +The most important part of the output is the `crashers` and `cover`. The crashers records how many combinations were discovered that fail and the cover tells you how much code is being accessed. +For a complete explanation of the output, please see: https://github.com/dvyukov/go-fuzz. + +The fuzzer will document the crashers in a folder labeled "crashers." It will record the fragment and the error that was produced in two separate files within this folder. This is the final product. + +Happy Fuzzing! diff --git a/roaring/fuzzer.go b/roaring/fuzzer.go new file mode 100644 index 000000000..9d31326a6 --- /dev/null +++ b/roaring/fuzzer.go @@ -0,0 +1,12 @@ +// +build gofuzz + +package roaring + +func FuzzBitmapUnmarshalBinary(data []byte) int { + b := NewBitmap() + err := b.UnmarshalBinary(data) + if err != nil { + return 0 + } + return 1 +} From 7182de5f302587fff0b7119f385a072cc313c299 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Fri, 14 Jun 2019 10:41:31 -0500 Subject: [PATCH 2/7] Added -bin -workdir and -func flags to README.md --- roaring/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roaring/README.md b/roaring/README.md index 3599a6813..1479e27c5 100644 --- a/roaring/README.md +++ b/roaring/README.md @@ -14,7 +14,7 @@ You must now make the workdir/corpus directory. This is achieved by: The fuzzer needs some input to start the fuzzing with. Copy some sample fragments into the workdir/corpus folder. Once you have copied your sample inputs, you are ready to run the fuzzer: -`go-fuzz` +`go-fuzz -bin=roaring-fuzz.zip -workdir=workdir -func=FuzzBitmapUnmarshalBianry` ## Understanding the Fuzzer Output From a00ef2760b1b667f1ca0c9aeb0f5bad93639a855 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Fri, 14 Jun 2019 11:11:53 -0500 Subject: [PATCH 3/7] Added Licensing --- roaring/fuzzer.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/roaring/fuzzer.go b/roaring/fuzzer.go index 9d31326a6..cf3483b9e 100644 --- a/roaring/fuzzer.go +++ b/roaring/fuzzer.go @@ -1,3 +1,17 @@ +// Copyright 2017 Pilosa Corp. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // +build gofuzz package roaring From f4157efcb98f7604d3c994d8d267925d223882a4 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Fri, 14 Jun 2019 11:46:13 -0500 Subject: [PATCH 4/7] Added Licensing --- roaring/fuzz_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 roaring/fuzz_test.go diff --git a/roaring/fuzz_test.go b/roaring/fuzz_test.go new file mode 100644 index 000000000..b11d00337 --- /dev/null +++ b/roaring/fuzz_test.go @@ -0,0 +1,44 @@ +// Copyright 2017 Pilosa Corp. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package roaring + +import ( + "testing" +) + +func TestUnmarshalBinary(t *testing.T) { + b := NewBitmap() + confirmedCrashers := []struct { + cr []byte + expected string + } { + { + cr : []byte(":0\x000\x01\x00\x00\x000000"), //":000000" + expected : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 12", + }, + { + cr : []byte("<0\x000\x00\x00\x00\x00000000000000" + + "0"), //"<000000000000000" + expected : "unmarshaling as pilosa roaring: too big", + }, + } + + for _, crash := range confirmedCrashers { + err := b.UnmarshalBinary(crash.cr) + if err.Error() != crash.expected { + t.Errorf("Expected: %s, Got: %s", crash.expected, err) + } + } + +} \ No newline at end of file From 81f8d80fe173074000a5f3438248601d41c7de79 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Mon, 17 Jun 2019 08:40:31 -0500 Subject: [PATCH 5/7] Provided example on how to copy Pilosa fragments in README.md --- roaring/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/roaring/README.md b/roaring/README.md index 1479e27c5..044c98b83 100644 --- a/roaring/README.md +++ b/roaring/README.md @@ -12,7 +12,11 @@ You must now make the workdir/corpus directory. This is achieved by: `mkdir workdir/corpus` -The fuzzer needs some input to start the fuzzing with. Copy some sample fragments into the workdir/corpus folder. Once you have copied your sample inputs, you are ready to run the fuzzer: +The fuzzer needs some input to start the fuzzing with. Copy some sample Pilosa fragments into the workdir/corpus folder. For example: + +`cp ~/.pilosa/my-index/my-field/views/standard/fragments/0 workdir/corpus` + +Once you have copied your sample inputs, you are ready to run the fuzzer: `go-fuzz -bin=roaring-fuzz.zip -workdir=workdir -func=FuzzBitmapUnmarshalBianry` From cae1a76629fbe20a2d394bc2e4a457ff05ae23e6 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Mon, 17 Jun 2019 16:47:28 -0500 Subject: [PATCH 6/7] Fixed typo --- roaring/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roaring/README.md b/roaring/README.md index 044c98b83..53269cf88 100644 --- a/roaring/README.md +++ b/roaring/README.md @@ -18,7 +18,7 @@ The fuzzer needs some input to start the fuzzing with. Copy some sample Pilosa f Once you have copied your sample inputs, you are ready to run the fuzzer: -`go-fuzz -bin=roaring-fuzz.zip -workdir=workdir -func=FuzzBitmapUnmarshalBianry` +`go-fuzz -bin=roaring-fuzz.zip -workdir=workdir -func=FuzzBitmapUnmarshalBinary` ## Understanding the Fuzzer Output From 97f525ff06b48a748abbc5dcfae51ec23dfb62db Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Tue, 18 Jun 2019 16:40:10 -0500 Subject: [PATCH 7/7] Removed fuzz_test.go --- roaring/fuzz_test.go | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 roaring/fuzz_test.go diff --git a/roaring/fuzz_test.go b/roaring/fuzz_test.go deleted file mode 100644 index b11d00337..000000000 --- a/roaring/fuzz_test.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2017 Pilosa Corp. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package roaring - -import ( - "testing" -) - -func TestUnmarshalBinary(t *testing.T) { - b := NewBitmap() - confirmedCrashers := []struct { - cr []byte - expected string - } { - { - cr : []byte(":0\x000\x01\x00\x00\x000000"), //":000000" - expected : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 12", - }, - { - cr : []byte("<0\x000\x00\x00\x00\x00000000000000" + - "0"), //"<000000000000000" - expected : "unmarshaling as pilosa roaring: too big", - }, - } - - for _, crash := range confirmedCrashers { - err := b.UnmarshalBinary(crash.cr) - if err.Error() != crash.expected { - t.Errorf("Expected: %s, Got: %s", crash.expected, err) - } - } - -} \ No newline at end of file