diff --git a/tools/ubsan/blacklist.txt b/tools/ubsan/blacklist.txt index 0d887e51bb..7a92cdbcba 100644 --- a/tools/ubsan/blacklist.txt +++ b/tools/ubsan/blacklist.txt @@ -22,6 +22,12 @@ src:*/usr/* # https://bugs.chromium.org/p/webrtc/issues/detail?id=5513 fun:*FilterBanksTest*CalculateResidualEnergyTester* +############################################################################# +# The audio processing AGC submodule exhibits a few problems (overflows). +# https://bugs.chromium.org/p/webrtc/issues/detail?id=5530 +src:*/webrtc/modules/audio_processing/agc/legacy/analog_agc.c +src:*/webrtc/modules/audio_processing/agc/legacy/digital_agc.c + ############################################################################# # Ignore errors in common_audio. # https://bugs.chromium.org/p/webrtc/issues/detail?id=5486 diff --git a/webrtc/modules/audio_processing/agc/legacy/analog_agc.c b/webrtc/modules/audio_processing/agc/legacy/analog_agc.c index 2450e05b76..36c67c282a 100644 --- a/webrtc/modules/audio_processing/agc/legacy/analog_agc.c +++ b/webrtc/modules/audio_processing/agc/legacy/analog_agc.c @@ -474,18 +474,18 @@ void WebRtcAgc_SaturationCtrl(LegacyAgc* stt, void WebRtcAgc_ZeroCtrl(LegacyAgc* stt, int32_t* inMicLevel, int32_t* env) { int16_t i; - int64_t tmp = 0; + int32_t tmp32 = 0; int32_t midVal; /* Is the input signal zero? */ for (i = 0; i < 10; i++) { - tmp += env[i]; + tmp32 += env[i]; } /* Each block is allowed to have a few non-zero * samples. */ - if (tmp < 500) { + if (tmp32 < 500) { stt->msZero += 10; } else { stt->msZero = 0; diff --git a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c index 231a2044a3..2ca967a4aa 100644 --- a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c +++ b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c @@ -189,7 +189,7 @@ int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16 // Calculate ratio // Shift |numFIX| as much as possible. // Ensure we avoid wrap-around in |den| as well. - if (numFIX > (den >> 8) || -numFIX > (den >> 8)) // |den| is Q8. + if (numFIX > (den >> 8)) // |den| is Q8. { zeros = WebRtcSpl_NormW32(numFIX); } else { @@ -198,11 +198,13 @@ int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16 numFIX *= 1 << zeros; // Q(14+zeros) // Shift den so we end up in Qy1 - tmp32no1 = WEBRTC_SPL_SHIFT_W32(den, zeros - 9); // Q(zeros - 1) - y32 = numFIX / tmp32no1; // in Q15 - // This is to do rounding in Q14. - y32 = y32 >= 0 ? (y32 + 1) >> 1 : -((-y32 + 1) >> 1); - + tmp32no1 = WEBRTC_SPL_SHIFT_W32(den, zeros - 8); // Q(zeros) + if (numFIX < 0) { + numFIX -= tmp32no1 / 2; + } else { + numFIX += tmp32no1 / 2; + } + y32 = numFIX / tmp32no1; // in Q14 if (limiterEnable && (i < limiterIdx)) { tmp32 = WEBRTC_SPL_MUL_16_U16(i - 1, kLog10_2); // Q14 tmp32 -= limiterLvl * (1 << 14); // Q14 diff --git a/webrtc/modules/audio_processing/gain_control_unittest.cc b/webrtc/modules/audio_processing/gain_control_unittest.cc index c3d1d6c246..c5de2369c5 100644 --- a/webrtc/modules/audio_processing/gain_control_unittest.cc +++ b/webrtc/modules/audio_processing/gain_control_unittest.cc @@ -218,7 +218,7 @@ TEST(GainControlBitExactnessTest, DISABLED_Mono8kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) { #endif const int kStreamAnalogLevelReference = 50; - const float kOutputReference[] = {-0.004028f, -0.001678f, 0.000946f}; + const float kOutputReference[] = {-0.006317f, -0.002625f, 0.001495f}; RunBitExactnessTest(8000, 1, GainControl::Mode::kAdaptiveDigital, 10, 50, 5, true, 0, 100, kStreamAnalogLevelReference, kOutputReference); @@ -233,7 +233,7 @@ TEST(GainControlBitExactnessTest, DISABLED_Mono16kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) { #endif const int kStreamAnalogLevelReference = 50; - const float kOutputReference[] = {-0.003967f, -0.002808f, -0.001770f}; + const float kOutputReference[] = {-0.006256f, -0.004395f, -0.002777f}; RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveDigital, 10, 50, 5, true, 0, 100, kStreamAnalogLevelReference, kOutputReference); @@ -248,8 +248,8 @@ TEST(GainControlBitExactnessTest, DISABLED_Stereo16kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) { #endif const int kStreamAnalogLevelReference = 50; - const float kOutputReference[] = {-0.015411f, -0.008972f, -0.015839f, - -0.015411f, -0.008972f, -0.015839f}; + const float kOutputReference[] = {-0.023956f, -0.013947f, -0.024597f, + -0.023956f, -0.013947f, -0.024597f}; RunBitExactnessTest(16000, 2, GainControl::Mode::kAdaptiveDigital, 10, 50, 5, true, 0, 100, kStreamAnalogLevelReference, kOutputReference); @@ -264,7 +264,7 @@ TEST(GainControlBitExactnessTest, DISABLED_Mono32kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) { #endif const int kStreamAnalogLevelReference = 50; - const float kOutputReference[] = {-0.006134f, -0.005554f, -0.005005f}; + const float kOutputReference[] = {-0.009644f, -0.008728f, -0.007904f}; RunBitExactnessTest(32000, 1, GainControl::Mode::kAdaptiveDigital, 10, 50, 5, true, 0, 100, kStreamAnalogLevelReference, kOutputReference); @@ -279,7 +279,7 @@ TEST(GainControlBitExactnessTest, DISABLED_Mono48kHz_AdaptiveDigital_Tl10_SL50_CG5_Lim_AL0_100) { #endif const int kStreamAnalogLevelReference = 50; - const float kOutputReference[] = {-0.006134f, -0.005554f, -0.005005f}; + const float kOutputReference[] = {-0.009644f, -0.008728f, -0.007904f}; RunBitExactnessTest(32000, 1, GainControl::Mode::kAdaptiveDigital, 10, 50, 5, true, 0, 100, kStreamAnalogLevelReference, kOutputReference); @@ -385,7 +385,7 @@ TEST(GainControlBitExactnessTest, DISABLED_Mono16kHz_AdaptiveAnalog_Tl10_SL100_CG5_Lim_AL70_80) { #endif const int kStreamAnalogLevelReference = 100; - const float kOutputReference[] = {-0.004028f, -0.002838f, -0.001801f}; + const float kOutputReference[] = {-0.006348f, -0.004456f, -0.002808f}; RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveAnalog, 10, 100, 5, true, 70, 80, kStreamAnalogLevelReference, kOutputReference); @@ -400,7 +400,7 @@ TEST(GainControlBitExactnessTest, DISABLED_Mono16kHz_AdaptiveDigital_Tl10_SL100_CG5_NoLim_AL0_100) { #endif const int kStreamAnalogLevelReference = 100; - const float kOutputReference[] = {-0.004028f, -0.002838f, -0.001801f}; + const float kOutputReference[] = {-0.006592f, -0.004639f, -0.002930f}; RunBitExactnessTest(16000, 1, GainControl::Mode::kAdaptiveDigital, 10, 100, 5, false, 0, 100, kStreamAnalogLevelReference, kOutputReference);