diff --git a/webrtc/common_audio/signal_processing/include/spl_inl.h b/webrtc/common_audio/signal_processing/include/spl_inl.h index 812ab2d587..370834e694 100644 --- a/webrtc/common_audio/signal_processing/include/spl_inl.h +++ b/webrtc/common_audio/signal_processing/include/spl_inl.h @@ -63,11 +63,6 @@ static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) { #endif } -static __inline int32_t WebRtcSpl_SatW64ToW32(int64_t x) { - int32_t x32 = (int32_t)x; - return x32 == x ? x32 : x < 0 ? INT32_MIN : INT32_MAX; -} - #ifdef WEBRTC_ARCH_ARM_V7 #include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h" #else diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c index e4d399b61f..039bbc8af7 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c @@ -26,7 +26,7 @@ #include "lpc_tables.h" #include "settings.h" #include "signal_processing_library.h" -#include "webrtc/base/checks.h" +#include "webrtc/base/sanitizer.h" /* * Eenumerations for arguments to functions WebRtcIsacfix_MatrixProduct1() @@ -189,6 +189,22 @@ static void CalcCorrelation(int32_t *PSpecQ12, int32_t *CorrQ7) } } +// Some arithmetic operations that are allowed to overflow. (It's still +// undefined behavior, so not a good idea; this just makes UBSan ignore the +// violations, so that our old code can continue to do what it's always been +// doing.) +static inline int32_t OverflowingMulS16S32ToS32(int16_t a, int32_t b) + RTC_NO_SANITIZE("signed-integer-overflow") { + return a * b; +} +static inline int32_t OverflowingAddS32S32ToS32(int32_t a, int32_t b) + RTC_NO_SANITIZE("signed-integer-overflow") { + return a + b; +} +static inline int32_t OverflowingSubS32S32ToS32(int32_t a, int32_t b) + RTC_NO_SANITIZE("signed-integer-overflow") { + return a - b; +} /* compute inverse AR power spectrum */ static void CalcInvArSpec(const int16_t *ARCoefQ12, @@ -231,11 +247,11 @@ static void CalcInvArSpec(const int16_t *ARCoefQ12, CurveQ16[n] = sum; for (k = 1; k < AR_ORDER; k += 2) { - for (n = 0; n < FRAMESAMPLES/8; n++) { - const int64_t p = - (WebRtcIsacfix_kCos[k][n] * (int64_t)CorrQ11[k + 1] + 2) >> 2; - CurveQ16[n] += WebRtcSpl_SatW64ToW32(p); - } + for (n = 0; n < FRAMESAMPLES/8; n++) + CurveQ16[n] += + (OverflowingMulS16S32ToS32(WebRtcIsacfix_kCos[k][n], CorrQ11[k + 1]) + + 2) >> + 2; } CS_ptrQ9 = WebRtcIsacfix_kCos[0]; @@ -261,8 +277,8 @@ static void CalcInvArSpec(const int16_t *ARCoefQ12, for (k=0; k> 2], 2195456)) >> - 16)); + gainQ10 = WebRtcSpl_DivW32W16ResW16(30 << 10, + (int16_t)((uint32_t)(invARSpec2_Q16[k >> 2] + 2195456) >> 16)); *frQ7++ = (int16_t)((data[k] * gainQ10 + 512) >> 10); *fiQ7++ = (int16_t)((data[k + 1] * gainQ10 + 512) >> 10); *frQ7++ = (int16_t)((data[k + 2] * gainQ10 + 512) >> 10); @@ -511,10 +525,8 @@ int WebRtcIsacfix_DecodeSpec(Bitstr_dec *streamdata, { for (k = 0; k < FRAMESAMPLES; k += 4) { - gainQ10 = WebRtcSpl_DivW32W16ResW16( - 36 << 10, (int16_t)((uint32_t)(WebRtcSpl_AddSatW32( - invARSpec2_Q16[k >> 2], 2654208)) >> - 16)); + gainQ10 = WebRtcSpl_DivW32W16ResW16(36 << 10, + (int16_t)((uint32_t)(invARSpec2_Q16[k >> 2] + 2654208) >> 16)); *frQ7++ = (int16_t)((data[k] * gainQ10 + 512) >> 10); *fiQ7++ = (int16_t)((data[k + 1] * gainQ10 + 512) >> 10); *frQ7++ = (int16_t)((data[k + 2] * gainQ10 + 512) >> 10);