1 /* 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include <algorithm> 12 13 #include "api/array_view.h" 14 #include "modules/audio_coding/codecs/cng/webrtc_cng.h" 15 #include "rtc_base/buffer.h" 16 #include "test/fuzzers/fuzz_data_helper.h" 17 18 namespace webrtc { 19 namespace test { 20 namespace { 21 FuzzOneInputTest(rtc::ArrayView<const uint8_t> data)22void FuzzOneInputTest(rtc::ArrayView<const uint8_t> data) { 23 FuzzDataHelper fuzz_data(data); 24 ComfortNoiseDecoder cng_decoder; 25 26 while (1) { 27 if (!fuzz_data.CanReadBytes(1)) 28 break; 29 const uint8_t sid_frame_len = fuzz_data.Read<uint8_t>(); 30 auto sid_frame = fuzz_data.ReadByteArray(sid_frame_len); 31 if (sid_frame.empty()) 32 break; 33 cng_decoder.UpdateSid(sid_frame); 34 if (!fuzz_data.CanReadBytes(3)) 35 break; 36 constexpr bool kTrueOrFalse[] = {true, false}; 37 const bool new_period = fuzz_data.SelectOneOf(kTrueOrFalse); 38 constexpr size_t kOutputSizes[] = {80, 160, 320, 480}; 39 const size_t output_size = fuzz_data.SelectOneOf(kOutputSizes); 40 const size_t num_generate_calls = 41 std::min(fuzz_data.Read<uint8_t>(), static_cast<uint8_t>(17)); 42 rtc::BufferT<int16_t> output(output_size); 43 for (size_t i = 0; i < num_generate_calls; ++i) { 44 cng_decoder.Generate(output, new_period); 45 } 46 } 47 } 48 49 } // namespace 50 } // namespace test 51 FuzzOneInput(const uint8_t * data,size_t size)52void FuzzOneInput(const uint8_t* data, size_t size) { 53 if (size > 5000) { 54 return; 55 } 56 test::FuzzOneInputTest(rtc::ArrayView<const uint8_t>(data, size)); 57 } 58 59 } // namespace webrtc 60