Added libldac-encode_fuzzer
Test: ./libldac-encode_fuzzer
Bug: 223483473
Change-Id: I78d6573c8aaf4013d7fe84a9e49f745301734338
diff --git a/fuzzer/Android.bp b/fuzzer/Android.bp
new file mode 100644
index 0000000..1d2620f
--- /dev/null
+++ b/fuzzer/Android.bp
@@ -0,0 +1,26 @@
+// 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.
+
+package {
+ default_applicable_licenses: ["external_libldac_license"],
+}
+
+cc_fuzz {
+ name: "libldac-encode_fuzzer",
+ shared_libs: ["libldacBT_enc"],
+ srcs: ["libldac_encode_fuzzer.cc"],
+ fuzz_config: {
+ componentid: 27441
+ },
+}
diff --git a/fuzzer/libldac_encode_fuzzer.cc b/fuzzer/libldac_encode_fuzzer.cc
new file mode 100644
index 0000000..2f293f1
--- /dev/null
+++ b/fuzzer/libldac_encode_fuzzer.cc
@@ -0,0 +1,47 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdint.h>
+#include <stddef.h>
+#include "ldacBT.h"
+
+#define TESTFUNC_TYPE extern "C" int
+
+TESTFUNC_TYPE
+LLVMFuzzerTestOneInput(const uint8_t *buf, size_t size)
+{
+ if (size == 0) {
+ return 0;
+ }
+ HANDLE_LDAC_BT hLdacBt;
+ int pcm_used, stream_sz, frame_num;
+ unsigned char p_stream[1024];
+
+ hLdacBt = ldacBT_get_handle();
+
+ ldacBT_init_handle_encode(
+ hLdacBt,
+ 679,
+ LDACBT_EQMID_SQ,
+ LDACBT_CHANNEL_MODE_DUAL_CHANNEL,
+ LDACBT_SMPL_FMT_S16,
+ 48000);
+
+ ldacBT_encode(
+ hLdacBt,
+ (void *)(&buf + 44),
+ &pcm_used,
+ p_stream,
+ &stream_sz,
+ &frame_num);
+
+ ldacBT_get_sampling_freq(hLdacBt);
+ ldacBT_get_bitrate(hLdacBt);
+ ldacBT_get_version();
+
+ ldacBT_close_handle(hLdacBt);
+ ldacBT_free_handle(hLdacBt);
+
+ return 0;
+}
diff --git a/fuzzer/ossfuzz.sh b/fuzzer/ossfuzz.sh
new file mode 100644
index 0000000..75b4658
--- /dev/null
+++ b/fuzzer/ossfuzz.sh
@@ -0,0 +1,27 @@
+# Copyright (C) 2022 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.
+#
+################################################################################
+
+$CC $CFLAGS -Iinc -c fuzzer/libldac_encode_fuzzer.cc -o libldac_encode_fuzzer.o
+$CC $CFLAGS -Iinc -c src/ldaclib.c -o src/ldaclib.o
+$CC $CFLAGS -Iinc -c src/ldacBT.c -o src/ldacBT.o
+
+$CXX $CXXFLAGS $LIB_FUZZING_ENGINE \
+ libldac_encode_fuzzer.o \
+ src/ldaclib.o \
+ src/ldacBT.o \
+ -o $OUT/libldac_encode_fuzzer
+
+zip -q $OUT/libldac_encode_fuzzer_seed_corpus.zip $SRC/corpora/*