1 /******************************************************************************
2 *
3 * Copyright (C) 2020 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************
18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "g711Dec.h"
25
26 class Codec {
27 public:
28 Codec() = default;
29 ~Codec() = default;
30 void decodeFrames(const uint8_t *data, size_t size);
31 };
32
decodeFrames(const uint8_t * data,size_t size)33 void Codec::decodeFrames(const uint8_t *data, size_t size) {
34 size_t outputBufferSize = sizeof(int16_t) * size;
35 int16_t *out = new int16_t[outputBufferSize];
36 if (!out) {
37 return;
38 }
39 #ifdef ALAW
40 DecodeALaw(out, data, size);
41 #else
42 DecodeMLaw(out, data, size);
43 #endif
44 delete[] out;
45 }
46
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)47 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
48 if (size < 1) {
49 return 0;
50 }
51 Codec *codec = new Codec();
52 if (!codec) {
53 return 0;
54 }
55 codec->decodeFrames(data, size);
56 delete codec;
57 return 0;
58 }
59