Loading media/extractors/fuzzers/Android.bp +22 −0 Original line number Diff line number Diff line Loading @@ -308,3 +308,25 @@ cc_fuzz { dictionary: "flac_extractor_fuzzer.dict", } cc_fuzz { name: "midi_extractor_fuzzer", defaults: ["extractor-fuzzer-defaults"], srcs: [ "midi_extractor_fuzzer.cpp", ], include_dirs: [ "frameworks/av/media/extractors/midi", ], static_libs: [ "libsonivox", "libmedia_midiiowrapper", "libmidiextractor", "libwatchdog", ], dictionary: "midi_extractor_fuzzer.dict", } media/extractors/fuzzers/README.md +36 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ + [libmp3extractor](#mp3ExtractorFuzzer) + [libaacextractor](#aacExtractorFuzzer) + [libflacextractor](#flacExtractor) + [libmidiextractor](#midiExtractorFuzzer) # <a name="ExtractorFuzzerBase"></a> Fuzzer for libextractorfuzzerbase All the extractors have a common API - creating a data source, extraction Loading Loading @@ -321,6 +322,41 @@ To run on device $ adb shell /data/fuzz/arm64/flac_extractor_fuzzer/flac_extractor_fuzzer CORPUS_DIR ``` # <a name="midiExtractorFuzzer"></a> Fuzzer for libmidiextractor ## Plugin Design Considerations The fuzzer plugin for MIDI extractor uses the `ExtractorFuzzerBase` class and implements only the `createExtractor` to create the MIDI extractor class. ##### Maximize code coverage Dict file (dictionary file) is created for MIDI to ensure that the required MIDI headers are present in every input file that goes to the fuzzer. This ensures that larger code gets covered as a range of MIDI headers will be present in the input data. ## Build This describes steps to build midi_extractor_fuzzer binary. ### Android #### Steps to build Build the fuzzer ``` $ mm -j$(nproc) midi_extractor_fuzzer ``` #### Steps to run Create a directory CORPUS_DIR and copy some MIDI files to that folder Push this directory to device. To run on device ``` $ adb sync data $ adb shell /data/fuzz/arm64/midi_extractor_fuzzer/midi_extractor_fuzzer CORPUS_DIR ``` ## References: * http://llvm.org/docs/LibFuzzer.html * https://github.com/google/oss-fuzz media/extractors/fuzzers/midi_extractor_fuzzer.cpp 0 → 100644 +54 −0 Original line number Diff line number Diff line /****************************************************************************** * * Copyright (C) 2020 The Android Open Source Project * * 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. * ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ #include "ExtractorFuzzerBase.h" #include "MidiExtractor.h" using namespace android; class MIDIExtractor : public ExtractorFuzzerBase { public: MIDIExtractor() = default; ~MIDIExtractor() = default; bool createExtractor(); }; bool MIDIExtractor::createExtractor() { mExtractor = new MidiExtractor(mDataSource->wrap()); if (!mExtractor) { return false; } mExtractor->name(); return true; } extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if ((!data) || (size == 0)) { return 0; } MIDIExtractor* extractor = new MIDIExtractor(); if (extractor) { extractor->processData(data, size); delete extractor; } return 0; } media/extractors/fuzzers/midi_extractor_fuzzer.dict 0 → 100644 +3 −0 Original line number Diff line number Diff line # MIDI Chunks kw1="MThd" kw2="MTrk" Loading
media/extractors/fuzzers/Android.bp +22 −0 Original line number Diff line number Diff line Loading @@ -308,3 +308,25 @@ cc_fuzz { dictionary: "flac_extractor_fuzzer.dict", } cc_fuzz { name: "midi_extractor_fuzzer", defaults: ["extractor-fuzzer-defaults"], srcs: [ "midi_extractor_fuzzer.cpp", ], include_dirs: [ "frameworks/av/media/extractors/midi", ], static_libs: [ "libsonivox", "libmedia_midiiowrapper", "libmidiextractor", "libwatchdog", ], dictionary: "midi_extractor_fuzzer.dict", }
media/extractors/fuzzers/README.md +36 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ + [libmp3extractor](#mp3ExtractorFuzzer) + [libaacextractor](#aacExtractorFuzzer) + [libflacextractor](#flacExtractor) + [libmidiextractor](#midiExtractorFuzzer) # <a name="ExtractorFuzzerBase"></a> Fuzzer for libextractorfuzzerbase All the extractors have a common API - creating a data source, extraction Loading Loading @@ -321,6 +322,41 @@ To run on device $ adb shell /data/fuzz/arm64/flac_extractor_fuzzer/flac_extractor_fuzzer CORPUS_DIR ``` # <a name="midiExtractorFuzzer"></a> Fuzzer for libmidiextractor ## Plugin Design Considerations The fuzzer plugin for MIDI extractor uses the `ExtractorFuzzerBase` class and implements only the `createExtractor` to create the MIDI extractor class. ##### Maximize code coverage Dict file (dictionary file) is created for MIDI to ensure that the required MIDI headers are present in every input file that goes to the fuzzer. This ensures that larger code gets covered as a range of MIDI headers will be present in the input data. ## Build This describes steps to build midi_extractor_fuzzer binary. ### Android #### Steps to build Build the fuzzer ``` $ mm -j$(nproc) midi_extractor_fuzzer ``` #### Steps to run Create a directory CORPUS_DIR and copy some MIDI files to that folder Push this directory to device. To run on device ``` $ adb sync data $ adb shell /data/fuzz/arm64/midi_extractor_fuzzer/midi_extractor_fuzzer CORPUS_DIR ``` ## References: * http://llvm.org/docs/LibFuzzer.html * https://github.com/google/oss-fuzz
media/extractors/fuzzers/midi_extractor_fuzzer.cpp 0 → 100644 +54 −0 Original line number Diff line number Diff line /****************************************************************************** * * Copyright (C) 2020 The Android Open Source Project * * 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. * ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ #include "ExtractorFuzzerBase.h" #include "MidiExtractor.h" using namespace android; class MIDIExtractor : public ExtractorFuzzerBase { public: MIDIExtractor() = default; ~MIDIExtractor() = default; bool createExtractor(); }; bool MIDIExtractor::createExtractor() { mExtractor = new MidiExtractor(mDataSource->wrap()); if (!mExtractor) { return false; } mExtractor->name(); return true; } extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if ((!data) || (size == 0)) { return 0; } MIDIExtractor* extractor = new MIDIExtractor(); if (extractor) { extractor->processData(data, size); delete extractor; } return 0; }
media/extractors/fuzzers/midi_extractor_fuzzer.dict 0 → 100644 +3 −0 Original line number Diff line number Diff line # MIDI Chunks kw1="MThd" kw2="MTrk"