1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <string> 18 #include <stddef.h> 19 #include <audio_utils/spdif/SPDIFEncoder.h> 20 #include <audio_utils/format.h> 21 #include <system/audio.h> 22 23 namespace android { 24 25 class MySPDIFEncoder : public SPDIFEncoder { 26 public: 27 explicit MySPDIFEncoder(audio_format_t format) 28 : SPDIFEncoder(format) { 29 } 30 31 ssize_t writeOutput(const void* buffer, size_t size) override { 32 if (buffer == nullptr) { 33 return 0; 34 } 35 return size; 36 } 37 }; 38 39 const static audio_format_t acs_formats[] = {AUDIO_FORMAT_AC3, AUDIO_FORMAT_E_AC3, 40 AUDIO_FORMAT_E_AC3_JOC}; 41 const size_t formats_len = sizeof(acs_formats)/sizeof(audio_format_t); 42 43 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 44 if (data == nullptr) { 45 return 0; 46 } 47 audio_format_t encoding = acs_formats[size % formats_len]; 48 MySPDIFEncoder scanner(encoding); 49 scanner.isFormatSupported(encoding); 50 scanner.write(data, size); // parsing will be triggered based on sync keywords found in dict 51 scanner.reset(); 52 return 0; 53 } 54 } 55