diff --git a/import/webrtc/common_audio/signal_processing/division_operations.c b/import/webrtc/common_audio/signal_processing/division_operations.c index eaa06a1..2d42052 100644 --- a/import/webrtc/common_audio/signal_processing/division_operations.c +++ b/import/webrtc/common_audio/signal_processing/division_operations.c @@ -22,6 +22,7 @@ */ #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" +#include "webrtc/rtc_base/sanitizer.h" uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den) { @@ -97,7 +98,8 @@ int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den) return div; } -int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low) +int32_t RTC_NO_SANITIZE("signed-integer-overflow") // bugs.webrtc.org/5486 +WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low) { int16_t approx, tmp_hi, tmp_low, num_hi, num_low; int32_t tmpW32; @@ -110,6 +112,7 @@ int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low) // tmpW32 = den * approx tmpW32 = (int32_t)0x7fffffffL - tmpW32; // result in Q30 (tmpW32 = 2.0-(den*approx)) + // UBSan: 2147483647 - -2 cannot be represented in type 'int' // Store tmpW32 in hi and low format tmp_hi = (int16_t)(tmpW32 >> 16); diff --git a/import/webrtc/common_audio/signal_processing/resample_by_2_internal.c b/import/webrtc/common_audio/signal_processing/resample_by_2_internal.c index 085069c..72bc0f9 100644 --- a/import/webrtc/common_audio/signal_processing/resample_by_2_internal.c +++ b/import/webrtc/common_audio/signal_processing/resample_by_2_internal.c @@ -15,6 +15,7 @@ */ #include "webrtc/common_audio/signal_processing/resample_by_2_internal.h" +#include "webrtc/rtc_base/sanitizer.h" // allpass filter coefficients. static const int16_t kResampleAllpass[2][3] = { @@ -28,8 +29,9 @@ static const int16_t kResampleAllpass[2][3] = { // output: int16_t (saturated) (of length len/2) // state: filter state array; length = 8 -void WebRtcSpl_DownBy2IntToShort(int32_t *in, int32_t len, int16_t *out, - int32_t *state) +void RTC_NO_SANITIZE("signed-integer-overflow") // bugs.webrtc.org/5486 +WebRtcSpl_DownBy2IntToShort(int32_t *in, int32_t len, int16_t *out, + int32_t *state) { int32_t tmp0, tmp1, diff; int32_t i; @@ -41,6 +43,8 @@ void WebRtcSpl_DownBy2IntToShort(int32_t *in, int32_t len, int16_t *out, { tmp0 = in[i << 1]; diff = tmp0 - state[1]; + // UBSan: -1771017321 - 999586185 cannot be represented in type 'int' + // scale down and round diff = (diff + (1 << 13)) >> 14; tmp1 = state[0] + diff * kResampleAllpass[1][0]; @@ -121,10 +125,11 @@ void WebRtcSpl_DownBy2IntToShort(int32_t *in, int32_t len, int16_t *out, // output: int32_t (shifted 15 positions to the left, + offset 16384) (of length len/2) // state: filter state array; length = 8 -void WebRtcSpl_DownBy2ShortToInt(const int16_t *in, - int32_t len, - int32_t *out, - int32_t *state) +void RTC_NO_SANITIZE("signed-integer-overflow") // bugs.webrtc.org/5486 +WebRtcSpl_DownBy2ShortToInt(const int16_t *in, + int32_t len, + int32_t *out, + int32_t *state) { int32_t tmp0, tmp1, diff; int32_t i; @@ -141,6 +146,8 @@ void WebRtcSpl_DownBy2ShortToInt(const int16_t *in, tmp1 = state[0] + diff * kResampleAllpass[1][0]; state[0] = tmp0; diff = tmp1 - state[2]; + // UBSan: -1379909682 - 834099714 cannot be represented in type 'int' + // scale down and truncate diff = diff >> 14; if (diff < 0) @@ -549,8 +556,9 @@ void WebRtcSpl_LPBy2ShortToInt(const int16_t* in, int32_t len, int32_t* out, // input: int32_t (shifted 15 positions to the left, + offset 16384) // output: int32_t (normalized, not saturated) // state: filter state array; length = 8 -void WebRtcSpl_LPBy2IntToInt(const int32_t* in, int32_t len, int32_t* out, - int32_t* state) +void RTC_NO_SANITIZE("signed-integer-overflow") // bugs.webrtc.org/5486 +WebRtcSpl_LPBy2IntToInt(const int32_t* in, int32_t len, int32_t* out, + int32_t* state) { int32_t tmp0, tmp1, diff; int32_t i; @@ -594,6 +602,8 @@ void WebRtcSpl_LPBy2IntToInt(const int32_t* in, int32_t len, int32_t* out, { tmp0 = in[i << 1]; diff = tmp0 - state[5]; + // UBSan: -794814117 - 1566149201 cannot be represented in type 'int' + // scale down and round diff = (diff + (1 << 13)) >> 14; tmp1 = state[4] + diff * kResampleAllpass[0][0]; diff --git a/import/webrtc/common_audio/signal_processing/signal_processing_unittest.cc b/import/webrtc/common_audio/signal_processing/signal_processing_unittest.cc index da6197e..52c4390 100644 --- a/import/webrtc/common_audio/signal_processing/signal_processing_unittest.cc +++ b/import/webrtc/common_audio/signal_processing/signal_processing_unittest.cc @@ -41,7 +41,6 @@ TEST_F(SplTest, MacroTest) { EXPECT_EQ(3, WEBRTC_SPL_ABS_W32(a)); EXPECT_EQ(-63, WEBRTC_SPL_MUL(a, B)); - EXPECT_EQ(-2147483645, WEBRTC_SPL_MUL(a, b)); EXPECT_EQ(2147483651u, WEBRTC_SPL_UMUL(a, b)); b = WEBRTC_SPL_WORD16_MAX >> 1; EXPECT_EQ(4294918147u, WEBRTC_SPL_UMUL_32_16(a, b));