Fix for overflow in iLBC code.
The calculation of the necessary number of shifts is not correct, leading to an overflow.
Bug: chromium:1158070
Change-Id: I6545e9da46debf33ce169c33d762915fe755d606
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/197981
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32855}
diff --git a/modules/audio_coding/codecs/ilbc/enhancer_interface.c b/modules/audio_coding/codecs/ilbc/enhancer_interface.c
index f85df6d7..74dfebb 100644
--- a/modules/audio_coding/codecs/ilbc/enhancer_interface.c
+++ b/modules/audio_coding/codecs/ilbc/enhancer_interface.c
@@ -202,10 +202,10 @@
/* scaling */
max16 = WebRtcSpl_MaxAbsValueW16(regressor, plc_blockl + 3 - 1);
- if (max16>5000)
- shifts=2;
- else
- shifts=0;
+
+ const int64_t max_val = plc_blockl * max16 * max16;
+ const int32_t factor = max_val >> 31;
+ shifts = factor == 0 ? 0 : 31 - WebRtcSpl_NormW32(factor);
/* compute cross correlation */
WebRtcSpl_CrossCorrelation(corr32, target, regressor, plc_blockl, 3, shifts,