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

Commit e73e7519 authored by Anuj Joshi's avatar Anuj Joshi
Browse files

Added aac_extractor_fuzzer

Test: ./aac_extractor_fuzzer
Bug: 151788604

Change-Id: Ic69eed728c94d92ffbdab9dad70554f8b78b1684
parent 11ab23ba
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -138,3 +138,30 @@ cc_fuzz {
        "libbinder",
    ],
}

cc_fuzz {
    name: "aac_extractor_fuzzer",

    srcs: [
        "aac_extractor_fuzzer.cpp",
    ],

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

    static_libs: [
        "liblog",
        "libstagefright_foundation",
        "libmedia",
        "libextractorfuzzerbase",
        "libaacextractor",
        "libstagefright_metadatautils",
    ],

    shared_libs: [
        "libutils",
        "libmediandk",
        "libbinder",
    ],
}
+30 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
+ [libmp4extractor](#mp4ExtractorFuzzer)
+ [libwavextractor](#wavExtractorFuzzer)
+ [libmp3extractor](#mp3ExtractorFuzzer)
+ [libaacextractor](#aacExtractorFuzzer)

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

# <a name="aacExtractorFuzzer"></a> Fuzzer for libaacextractor

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


## Build

This describes steps to build aac_extractor_fuzzer binary.

### Android

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

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

To run on device
```
  $ adb sync data
  $ adb shell /data/fuzz/arm64/aac_extractor_fuzzer/aac_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 "AACExtractor.h"

#include "ExtractorFuzzerBase.h"

using namespace android;

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

  bool createExtractor();
};

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