Loading system/embdrv/lc3_enc/Android.bp +12 −0 Original line number Diff line number Diff line Loading @@ -46,3 +46,15 @@ cc_library_static { "include", ], } cc_fuzz { name: "liblc3encoder_fuzzer", srcs: [ "fuzzer/liblc3encoder_fuzzer.cpp", ], static_libs: [ "liblc3encoder", ], } system/embdrv/lc3_enc/fuzzer/liblc3encoder_fuzzer.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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. */ #include <fuzzer/FuzzedDataProvider.h> #include "include/lc3.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { FuzzedDataProvider fdp(data, size); int dt_us = fdp.PickValueInArray({10000, 7500}); int sr_hz = fdp.PickValueInArray({8000, 16000, 24000, 32000, /*44100,*/ 48000}); unsigned enc_size = lc3_encoder_size(dt_us, sr_hz); uint16_t output_byte_count = fdp.ConsumeIntegralInRange(20, 400); uint16_t num_frames = lc3_frame_samples(dt_us, sr_hz); if (fdp.remaining_bytes() < num_frames * 2) { return 0; } std::vector<uint16_t> input_frames(num_frames); fdp.ConsumeData(input_frames.data(), input_frames.size() * 2 /* each frame is 2 bytes */); void* lc3_encoder_mem = nullptr; lc3_encoder_mem = malloc(enc_size); lc3_encoder_t lc3_encoder = lc3_setup_encoder(dt_us, sr_hz, lc3_encoder_mem); std::vector<uint8_t> output(output_byte_count); lc3_encode(lc3_encoder, (const int16_t*)input_frames.data(), 1, output.data(), output.size()); free(lc3_encoder_mem); lc3_encoder_mem = nullptr; return 0; } No newline at end of file Loading
system/embdrv/lc3_enc/Android.bp +12 −0 Original line number Diff line number Diff line Loading @@ -46,3 +46,15 @@ cc_library_static { "include", ], } cc_fuzz { name: "liblc3encoder_fuzzer", srcs: [ "fuzzer/liblc3encoder_fuzzer.cpp", ], static_libs: [ "liblc3encoder", ], }
system/embdrv/lc3_enc/fuzzer/liblc3encoder_fuzzer.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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. */ #include <fuzzer/FuzzedDataProvider.h> #include "include/lc3.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { FuzzedDataProvider fdp(data, size); int dt_us = fdp.PickValueInArray({10000, 7500}); int sr_hz = fdp.PickValueInArray({8000, 16000, 24000, 32000, /*44100,*/ 48000}); unsigned enc_size = lc3_encoder_size(dt_us, sr_hz); uint16_t output_byte_count = fdp.ConsumeIntegralInRange(20, 400); uint16_t num_frames = lc3_frame_samples(dt_us, sr_hz); if (fdp.remaining_bytes() < num_frames * 2) { return 0; } std::vector<uint16_t> input_frames(num_frames); fdp.ConsumeData(input_frames.data(), input_frames.size() * 2 /* each frame is 2 bytes */); void* lc3_encoder_mem = nullptr; lc3_encoder_mem = malloc(enc_size); lc3_encoder_t lc3_encoder = lc3_setup_encoder(dt_us, sr_hz, lc3_encoder_mem); std::vector<uint8_t> output(output_byte_count); lc3_encode(lc3_encoder, (const int16_t*)input_frames.data(), 1, output.data(), output.size()); free(lc3_encoder_mem); lc3_encoder_mem = nullptr; return 0; } No newline at end of file