From 0ff2b4cd4265a1a3453c42f6ce7ae4220ec08ff1 Mon Sep 17 00:00:00 2001 From: Ivo Creusen Date: Wed, 16 Dec 2020 17:37:58 +0100 Subject: [PATCH] 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 Commit-Queue: Ivo Creusen Cr-Commit-Position: refs/heads/master@{#32855} --- modules/audio_coding/codecs/ilbc/enhancer_interface.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/audio_coding/codecs/ilbc/enhancer_interface.c b/modules/audio_coding/codecs/ilbc/enhancer_interface.c index f85df6d7ce..74dfebb47d 100644 --- a/modules/audio_coding/codecs/ilbc/enhancer_interface.c +++ b/modules/audio_coding/codecs/ilbc/enhancer_interface.c @@ -202,10 +202,10 @@ size_t // (o) Estimated lag in end of in[] /* 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,