Adding fuzzer for PCM16b decoder and fixing a fuzzer problem
Bug: chromium:1280852 Change-Id: I7f6c5de86ceee01156743c0389c59f875e53bb5f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251580 Reviewed-by: Minyue Li <minyue@webrtc.org> Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36005}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
e47493b3c0
commit
ac341df436
@ -42,7 +42,12 @@ int AudioDecoderPcm16B::DecodeInternal(const uint8_t* encoded,
|
|||||||
int16_t* decoded,
|
int16_t* decoded,
|
||||||
SpeechType* speech_type) {
|
SpeechType* speech_type) {
|
||||||
RTC_DCHECK_EQ(sample_rate_hz_, sample_rate_hz);
|
RTC_DCHECK_EQ(sample_rate_hz_, sample_rate_hz);
|
||||||
size_t ret = WebRtcPcm16b_Decode(encoded, encoded_len, decoded);
|
// Adjust the encoded length down to ensure the same number of samples in each
|
||||||
|
// channel.
|
||||||
|
const size_t encoded_len_adjusted =
|
||||||
|
PacketDuration(encoded, encoded_len) * 2 *
|
||||||
|
Channels(); // 2 bytes per sample per channel
|
||||||
|
size_t ret = WebRtcPcm16b_Decode(encoded, encoded_len_adjusted, decoded);
|
||||||
*speech_type = ConvertSpeechType(1);
|
*speech_type = ConvertSpeechType(1);
|
||||||
return static_cast<int>(ret);
|
return static_cast<int>(ret);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -308,6 +308,14 @@ webrtc_fuzzer_test("audio_decoder_multiopus_fuzzer") {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webrtc_fuzzer_test("audio_decoder_pcm16b_fuzzer") {
|
||||||
|
sources = [ "audio_decoder_pcm16b_fuzzer.cc" ]
|
||||||
|
deps = [
|
||||||
|
":audio_decoder_fuzzer",
|
||||||
|
"../../modules/audio_coding:pcm16b",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
rtc_library("audio_encoder_fuzzer") {
|
rtc_library("audio_encoder_fuzzer") {
|
||||||
testonly = true
|
testonly = true
|
||||||
sources = [
|
sources = [
|
||||||
|
|||||||
56
test/fuzzers/audio_decoder_pcm16b_fuzzer.cc
Normal file
56
test/fuzzers/audio_decoder_pcm16b_fuzzer.cc
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.h"
|
||||||
|
#include "test/fuzzers/audio_decoder_fuzzer.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||||
|
if (size > 10000 || size < 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sample_rate_hz;
|
||||||
|
switch (data[0] % 4) {
|
||||||
|
case 0:
|
||||||
|
sample_rate_hz = 8000;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
sample_rate_hz = 16000;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
sample_rate_hz = 32000;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
sample_rate_hz = 48000;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
RTC_DCHECK_NOTREACHED();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const size_t num_channels = data[1] % 16 + 1;
|
||||||
|
|
||||||
|
// Two first bytes of the data are used. Move forward.
|
||||||
|
data += 2;
|
||||||
|
size -= 2;
|
||||||
|
|
||||||
|
AudioDecoderPcm16B dec(sample_rate_hz, num_channels);
|
||||||
|
// Allocate a maximum output size of 100 ms.
|
||||||
|
const size_t allocated_ouput_size_samples =
|
||||||
|
sample_rate_hz * num_channels / 10;
|
||||||
|
std::unique_ptr<int16_t[]> output =
|
||||||
|
std::make_unique<int16_t[]>(allocated_ouput_size_samples);
|
||||||
|
FuzzAudioDecoder(
|
||||||
|
DecoderFunctionType::kNormalDecode, data, size, &dec, sample_rate_hz,
|
||||||
|
allocated_ouput_size_samples * sizeof(int16_t), output.get());
|
||||||
|
}
|
||||||
|
} // namespace webrtc
|
||||||
Reference in New Issue
Block a user