Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9ead02a authored by Kris Alder's avatar Kris Alder Committed by Automerger Merge Worker
Browse files

Merge "Added wav_extractor_fuzzer" am: b943f817

Change-Id: I4aeb519d29258f1742e0999c6bc9312a5209ced7
parents a91f88eb b943f817
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -81,3 +81,32 @@ cc_fuzz {

    dictionary: "mp4_extractor_fuzzer.dict",
}

cc_fuzz {
    name: "wav_extractor_fuzzer",

    srcs: [
        "wav_extractor_fuzzer.cpp",
    ],

    include_dirs: [
        "frameworks/av/media/extractors/wav",
    ],

    static_libs: [
        "liblog",
        "libstagefright_foundation",
        "libmedia",
        "libextractorfuzzerbase",
        "libfifo",
        "libwavextractor",
    ],

    shared_libs: [
        "libutils",
        "libmediandk",
        "libbinder",
        "libbinder_ndk",
        "libbase",
    ],
}
+30 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
## Table of contents
1. [libextractorfuzzerbase](#ExtractorFuzzerBase)
2. [libmp4extractor](#mp4ExtractorFuzzer)
3. [libwavextractor](#wavExtractorFuzzer)

# <a name="ExtractorFuzzerBase"></a> Fuzzer for libextractorfuzzerbase
All the extractors have a common API - creating a data source, extraction
@@ -49,6 +50,35 @@ To run on device
  $ adb shell /data/fuzz/arm64/mp4_extractor_fuzzer/mp4_extractor_fuzzer CORPUS_DIR
```

# <a name="wavExtractorFuzzer"></a> Fuzzer for libwavextractor

## Plugin Design Considerations
The fuzzer plugin for WAV extractor uses the `ExtractorFuzzerBase` class and
implements only the `createExtractor` to create the WAV extractor class.


## Build

This describes steps to build wav_extractor_fuzzer binary.

### Android

#### Steps to build
Build the fuzzer
```
  $ mm -j$(nproc) wav_extractor_fuzzer
```

#### Steps to run
Create a directory CORPUS_DIR and copy some wav files to that folder
Push this directory to device.

To run on device
```
  $ adb sync data
  $ adb shell /data/fuzz/arm64/wav_extractor_fuzzer/wav_extractor_fuzzer CORPUS_DIR
```

## References:
 * http://llvm.org/docs/LibFuzzer.html
 * https://github.com/google/oss-fuzz
+62 −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 "WAVExtractor.h"

using namespace android;

class wavExtractor : public ExtractorFuzzerBase {
 public:
  wavExtractor() = default;
  ~wavExtractor() = default;

  bool createExtractor();
};

bool wavExtractor::createExtractor() {
  mExtractor = new WAVExtractor(new DataSourceHelper(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;
  }
  wavExtractor* extractor = new wavExtractor();
  if (!extractor) {
    return 0;
  }
  if (extractor->setDataSource(data, size)) {
    if (extractor->createExtractor()) {
      extractor->getExtractorDef();
      extractor->getMetadata();
      extractor->extractTracks();
      extractor->getTracksMetadata();
    }
  }
  delete extractor;
  return 0;
}