Fuzzer crash in AGC2.
Gain specified by fuzzer in APM config was too high.
Bug: chromium:901661
Change-Id: Id3ea8d23a4284a35c827bb16125902d84e37ca1e
Reviewed-on: https://webrtc-review.googlesource.com/c/110604
Commit-Queue: Alex Loiko <aleloi@webrtc.org>
Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25594}
diff --git a/modules/audio_processing/gain_controller2.cc b/modules/audio_processing/gain_controller2.cc
index f256be0..06ad8f5 100644
--- a/modules/audio_processing/gain_controller2.cc
+++ b/modules/audio_processing/gain_controller2.cc
@@ -62,13 +62,15 @@
void GainController2::ApplyConfig(
const AudioProcessing::Config::GainController2& config) {
- RTC_DCHECK(Validate(config));
- config_ = config;
- if (gain_applier_.GetGainFactor() != config_.fixed_gain_db) {
+ RTC_DCHECK(Validate(config))
+ << " the invalid config was " << ToString(config);
+
+ if (config.fixed_gain_db != config_.fixed_gain_db) {
// Reset the limiter to quickly react on abrupt level changes caused by
// large changes of the fixed gain.
limiter_.Reset();
}
+ config_ = config;
gain_applier_.SetGainFactor(DbToRatio(config_.fixed_gain_db));
adaptive_digital_mode_ = config_.adaptive_digital_mode;
adaptive_agc_.reset(
@@ -77,7 +79,7 @@
bool GainController2::Validate(
const AudioProcessing::Config::GainController2& config) {
- return config.fixed_gain_db >= 0.f &&
+ return config.fixed_gain_db >= 0.f && config.fixed_gain_db < 50.f &&
config.extra_saturation_margin_db >= 0.f &&
config.extra_saturation_margin_db <= 100.f;
}
diff --git a/modules/audio_processing/gain_controller2_unittest.cc b/modules/audio_processing/gain_controller2_unittest.cc
index caaefdd..f469bc7 100644
--- a/modules/audio_processing/gain_controller2_unittest.cc
+++ b/modules/audio_processing/gain_controller2_unittest.cc
@@ -117,7 +117,7 @@
EXPECT_FALSE(GainController2::Validate(config));
// Check that valid configurations are applied.
- for (const float& fixed_gain_db : {0.f, 5.f, 10.f, 50.f}) {
+ for (const float& fixed_gain_db : {0.f, 5.f, 10.f, 40.f}) {
config.fixed_gain_db = fixed_gain_db;
EXPECT_TRUE(GainController2::Validate(config));
gain_controller2->ApplyConfig(config);
diff --git a/test/fuzzers/audio_processing_configs_fuzzer.cc b/test/fuzzers/audio_processing_configs_fuzzer.cc
index 6bbd0c0..95bdf09 100644
--- a/test/fuzzers/audio_processing_configs_fuzzer.cc
+++ b/test/fuzzers/audio_processing_configs_fuzzer.cc
@@ -89,7 +89,7 @@
// Read an int8 value, but don't let it be too large or small.
const float gain_controller2_gain_db =
- rtc::SafeClamp<int>(fuzz_data->ReadOrDefaultValue<int8_t>(0), -50, 50);
+ rtc::SafeClamp<int>(fuzz_data->ReadOrDefaultValue<int8_t>(0), -40, 40);
constexpr size_t kNumFieldTrials = arraysize(kFieldTrialNames);
// Verify that the read data type has enough bits to fuzz the field trials.