Skip to content

Commit

Permalink
Move UBSan warnings from a blacklist to the source
Browse files Browse the repository at this point in the history
This is done to make UBSan testing more convenient in integration with projects using WebRTC

Some blacklist entries were obsolete so don't need a replacement

Also fix one of the warnings (thanks, kwiberg@)

BUG=webrtc:8189, webrtc:5486, webrtc:5491

Review-Url: https://codereview.webrtc.org/3009123002
Cr-Commit-Position: refs/heads/master@{#19682}
  • Loading branch information
oprypin authored and dpirch committed May 1, 2018
1 parent 49b777c commit 8349e58
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand All @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 8349e58

Please sign in to comment.