1*c8dee2aaSAndroid Build Coastguard Worker#Fuzzing 2*c8dee2aaSAndroid Build Coastguard WorkerIn this folder, we keep our _fuzzers_ (bits of code that takes a randomized input and executes code 3*c8dee2aaSAndroid Build Coastguard Workerrandomly, focusing on specific APIs). For example, we have a codec fuzzer which takes a mutated 4*c8dee2aaSAndroid Build Coastguard Workerpng/jpeg or similar file and attempts to turn it into an `SkImage`. We also have a canvas fuzzer 5*c8dee2aaSAndroid Build Coastguard Workerwhich takes in a random set of bytes and turns them into calls on `SkCanvas`. 6*c8dee2aaSAndroid Build Coastguard Worker 7*c8dee2aaSAndroid Build Coastguard Worker## Executables 8*c8dee2aaSAndroid Build Coastguard WorkerThese fuzzers are packaged in two different ways (see //BUILD.gn). There is a `fuzz` executable 9*c8dee2aaSAndroid Build Coastguard Workerthat contains all fuzzers and is a convenient way to reproduce fuzzer-reported bugs. There are also 10*c8dee2aaSAndroid Build Coastguard Workersingle fuzzer executables containing exactly one fuzzer, which are convenient to build with 11*c8dee2aaSAndroid Build Coastguard Worker[libfuzzer](https://llvm.org/docs/LibFuzzer.html). 12*c8dee2aaSAndroid Build Coastguard Worker 13*c8dee2aaSAndroid Build Coastguard WorkerSee [../site/dev/testing/fuzz.md] for more information on building and running fuzzers using the 14*c8dee2aaSAndroid Build Coastguard Worker`fuzz` executable. 15*c8dee2aaSAndroid Build Coastguard Worker 16*c8dee2aaSAndroid Build Coastguard Worker## Continuous Running 17*c8dee2aaSAndroid Build Coastguard WorkerWe fuzz Skia using [OSS-Fuzz](https://github.com/google/oss-fuzz), which in turn uses fuzzing 18*c8dee2aaSAndroid Build Coastguard Workerengines such as libfuzzer, afl-fuzz, hong-fuzz, and others to fuzz Skia. OSS-Fuzz will automatically 19*c8dee2aaSAndroid Build Coastguard Worker[file and close bugs](https://bugs.chromium.org/p/oss-fuzz/issues/list?q=label:Proj-skia) when 20*c8dee2aaSAndroid Build Coastguard Workerit finds issues. 21*c8dee2aaSAndroid Build Coastguard Worker 22*c8dee2aaSAndroid Build Coastguard WorkerThere is a [Skia folder](https://github.com/google/oss-fuzz/tree/master/projects/skia) 23*c8dee2aaSAndroid Build Coastguard Workerin the OSS-Fuzz repo that we make changes to when we want to add/remove/change the fuzzers that 24*c8dee2aaSAndroid Build Coastguard Workerare automatically run. 25*c8dee2aaSAndroid Build Coastguard Worker[This](https://google.github.io/oss-fuzz/getting-started/new-project-guide/#testing-locally) 26*c8dee2aaSAndroid Build Coastguard Workerdescribes how to test the OSS-Fuzz build and fuzzers locally using Docker. 27*c8dee2aaSAndroid Build Coastguard Worker 28*c8dee2aaSAndroid Build Coastguard WorkerWhen enabling a fuzzer in OSS-Fuzz, we typically need to follow these steps: 29*c8dee2aaSAndroid Build Coastguard Worker 1. *Add a seed corpus to `gs://skia-fuzzer/oss-fuzz/` (in the 30*c8dee2aaSAndroid Build Coastguard Worker [skia-public project](https://console.cloud.google.com/storage/browser/skia-fuzzer?project=skia-public)). 31*c8dee2aaSAndroid Build Coastguard Worker Make sure the corpus file is public-readable. It is easiest to add this permission via the web 32*c8dee2aaSAndroid Build Coastguard Worker UI. This is done by granting the allUsers "name" the Reader role to the zip file. See the infra 33*c8dee2aaSAndroid Build Coastguard Worker team if you do not have access to this bucket. 34*c8dee2aaSAndroid Build Coastguard Worker 2. *Update [the Dockerfile](https://github.com/google/oss-fuzz/blob/master/projects/skia/Dockerfile) 35*c8dee2aaSAndroid Build Coastguard Worker to download the seed corpus to the build image. 36*c8dee2aaSAndroid Build Coastguard Worker 3. Update [build.sh](https://github.com/google/oss-fuzz/blob/628264df27f53cc60fcb27406a2da05d2197c025/projects/skia/build.sh#L99) 37*c8dee2aaSAndroid Build Coastguard Worker to build the desired fuzzer target and move it into $OUT. If there is a seed corpus, move 38*c8dee2aaSAndroid Build Coastguard Worker it into $OUT and make sure it is the same name as the fuzzer executable with `_seed_corpus.zip` 39*c8dee2aaSAndroid Build Coastguard Worker as a suffix. 40*c8dee2aaSAndroid Build Coastguard Worker 41*c8dee2aaSAndroid Build Coastguard Worker*For fuzzers who depend strongly on the format of the randomized data, e.g. image decoding, SkSL 42*c8dee2aaSAndroid Build Coastguard Workerparsing. These are called _binary fuzzers_, as opposed to _API fuzzers_. 43*c8dee2aaSAndroid Build Coastguard Worker 44*c8dee2aaSAndroid Build Coastguard WorkerExample PRs for adding fuzzers: [binary](https://github.com/google/oss-fuzz/pull/4108), 45*c8dee2aaSAndroid Build Coastguard Worker[API](https://github.com/google/oss-fuzz/pull/5657) 46*c8dee2aaSAndroid Build Coastguard Worker 47*c8dee2aaSAndroid Build Coastguard WorkerThere is also an [OSS-Fuzz folder](https://github.com/google/oss-fuzz/tree/master/projects/skcms) 48*c8dee2aaSAndroid Build Coastguard Workerset up for the [skcms repo](https://skia.googlesource.com/skcms/). The build process is similar, 49*c8dee2aaSAndroid Build Coastguard Workerexcept instead of compiling using GN targets, the build.sh script compiles the fuzz executables 50*c8dee2aaSAndroid Build Coastguard Workerdirectly. 51*c8dee2aaSAndroid Build Coastguard Worker 52*c8dee2aaSAndroid Build Coastguard Worker### OSS-Fuzz dashboard 53*c8dee2aaSAndroid Build Coastguard Worker<https://oss-fuzz.com/fuzzer-stats> is useful to see metrics on how our fuzzers are running. It 54*c8dee2aaSAndroid Build Coastguard Workershows things like executions per second (higher is better), edge coverage percent per fuzzer, 55*c8dee2aaSAndroid Build Coastguard Workerwhat percent of fuzzing runs end in OOM/timeout/crash, the entire corpus of fuzzed inputs 56*c8dee2aaSAndroid Build Coastguard Worker(corpus_backup), etc. Contact aarya@ to get permission to view this dashboard if necessary. 57*c8dee2aaSAndroid Build Coastguard WorkerHere are some example dashboards: 58*c8dee2aaSAndroid Build Coastguard Worker 59*c8dee2aaSAndroid Build Coastguard Worker - [Per Fuzzer summary for all Skia fuzzers driven by libFuzzer](https://oss-fuzz.com/fuzzer-stats?group_by=by-fuzzer&date_start=2021-08-16&date_end=2021-08-22&fuzzer=libFuzzer&job=libfuzzer_asan_skia&project=skia) 60*c8dee2aaSAndroid Build Coastguard Worker - [Five day summary of sksl2glsl driven by afl-fuzz](https://oss-fuzz.com/fuzzer-stats?group_by=by-day&date_start=2021-08-16&date_end=2021-08-22&fuzzer=afl_skia_sksl2glsl&job=afl_asan_skia&project=skia) 61*c8dee2aaSAndroid Build Coastguard Worker 62*c8dee2aaSAndroid Build Coastguard WorkerOSS-Fuzz also offers [a combined Coverage Report from all Skia fuzzers](https://oss-fuzz.com/coverage-report/job/libfuzzer_asan_skia/latest). 63*c8dee2aaSAndroid Build Coastguard Worker[Example coverage report from 2021 Aug 22](https://storage.googleapis.com/oss-fuzz-coverage/skia/reports/20210822/linux/report.html) 64*c8dee2aaSAndroid Build Coastguard Worker 65*c8dee2aaSAndroid Build Coastguard Worker## See Also 66*c8dee2aaSAndroid Build Coastguard Worker - [Creating a binary fuzzer](https://docs.google.com/document/d/1QDX0o8yDdmhbjoudNsXc66iuRXRF5XNNqGnzDzX7c2I/edit) 67*c8dee2aaSAndroid Build Coastguard Worker - [Creating an API fuzzer](https://docs.google.com/document/d/1e3ikXO7SwoBsbsi1MF06vydXRlXvYalVORaiUuOXk2Y/edit)