From c531af77c3e02332047fcaea2eccec945fdfbab5 Mon Sep 17 00:00:00 2001 From: Alex Loiko Date: Tue, 24 Oct 2017 10:41:48 +0200 Subject: [PATCH] Fix 'Left shift cannot be represented in int32_t'. In the legacy C part of AGC, an audio level 'cur_level' is represented as (1+frac) * 2^(31 - zeros) The 'zeros' exponent part is used for looking up a gain value in a table, and 'frac' is used for interpolating between two nearby table values. Code snippet below: zeros = WebRtcSpl_NormU32((uint32_t)cur_level); tmp32 = (cur_level << zeros) & 0x7FFFFFFF; frac = (int16_t)(tmp32 >> 19); In the second line, 'cur_level' is shifted upwards so that the leading bit is '1', after which the leading bit is cleared. The result is 'frac' in Q31. The compiler type of 'cur_level << zeros' is 'int32_t'. This is a fuzzer error 'Left shift cannot be represented in int32_t', because the leading sign bit is 1. This CL changes the compiler type to uint32_t. Bug: chromium:776286 Change-Id: Ie29552b75e690057bd76fc88e747841b531e3802 Reviewed-on: https://webrtc-review.googlesource.com/14841 Reviewed-by: Alessio Bazzica Commit-Queue: Alex Loiko Cr-Commit-Position: refs/heads/master@{#20405} --- modules/audio_processing/agc/legacy/digital_agc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/audio_processing/agc/legacy/digital_agc.c b/modules/audio_processing/agc/legacy/digital_agc.c index 8353f85f67..fe4e5cee6c 100644 --- a/modules/audio_processing/agc/legacy/digital_agc.c +++ b/modules/audio_processing/agc/legacy/digital_agc.c @@ -410,7 +410,7 @@ int32_t WebRtcAgc_ProcessDigital(DigitalAgc* stt, if (cur_level == 0) { zeros = 31; } - tmp32 = (cur_level << zeros) & 0x7FFFFFFF; + tmp32 = ((uint32_t)cur_level << zeros) & 0x7FFFFFFF; frac = (int16_t)(tmp32 >> 19); // Q12. tmp32 = (stt->gainTable[zeros - 1] - stt->gainTable[zeros]) * frac; gains[k + 1] = stt->gainTable[zeros] + (tmp32 >> 12); @@ -429,7 +429,7 @@ int32_t WebRtcAgc_ProcessDigital(DigitalAgc* stt, if (stt->capacitorFast == 0) { zeros_fast = 31; } - tmp32 = (stt->capacitorFast << zeros_fast) & 0x7FFFFFFF; + tmp32 = ((uint32_t)stt->capacitorFast << zeros_fast) & 0x7FFFFFFF; zeros_fast <<= 9; zeros_fast -= (int16_t)(tmp32 >> 22);