Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: webrtc/common_audio/vad/vad_core.c

Issue 2318083002: VadCore: Allow signed multiplication overflow that we don't know how to fix (Closed)
Patch Set: Handle compilers that define __clang__ but don't have the no_sanitize attribute Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/sanitizer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_audio/vad/vad_core.c
diff --git a/webrtc/common_audio/vad/vad_core.c b/webrtc/common_audio/vad/vad_core.c
index 51797eed549440f0b10f5dea7312792b2f4bb819..0340165eb5050ec9fbc386f6d373d0d90a4868f1 100644
--- a/webrtc/common_audio/vad/vad_core.c
+++ b/webrtc/common_audio/vad/vad_core.c
@@ -10,6 +10,7 @@
#include "webrtc/common_audio/vad/vad_core.h"
+#include "webrtc/base/sanitizer.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
#include "webrtc/common_audio/vad/vad_filterbank.h"
#include "webrtc/common_audio/vad/vad_gmm.h"
@@ -110,6 +111,15 @@ static int32_t WeightedAverage(int16_t* data, int16_t offset,
return weighted_average;
}
+// An s16 x s32 -> s32 multiplication that's allowed to overflow. (It's still
+// undefined behavior, so not a good idea; this just makes UBSan ignore the
+// violation, so that our old code can continue to do what it's always been
+// doing.)
+static inline int32_t OverflowingMulS16ByS32ToS32(int16_t a, int32_t b)
+ RTC_NO_SANITIZE("signed-integer-overflow") {
+ return a * b;
+}
+
// Calculates the probabilities for both speech and background noise using
// Gaussian Mixture Models (GMM). A hypothesis-test is performed to decide which
// type of signal is most probable.
@@ -378,7 +388,7 @@ static int16_t GmmProbability(VadInstT* self, int16_t* features,
// (Q14 >> 2) * Q12 = Q24.
tmp_s16 = (ngprvec[gaussian] + 2) >> 2;
- tmp2_s32 = tmp_s16 * tmp1_s32;
+ tmp2_s32 = OverflowingMulS16ByS32ToS32(tmp_s16, tmp1_s32);
// Q20 * approx 0.001 (2^-10=0.0009766), hence,
// (Q24 >> 14) = (Q24 >> 4) / 2^10 = Q20.
tmp1_s32 = tmp2_s32 >> 14;
« no previous file with comments | « webrtc/base/sanitizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698