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

Side by Side Diff: webrtc/modules/audio_coding/codecs/ilbc/smooth.c

Issue 2014033002: Fix UBSan errors (signed integer overflow) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@bug601787-2
Patch Set: Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 13 matching lines...) Expand all
24 * find the smoothed output data 24 * find the smoothed output data
25 *---------------------------------------------------------------*/ 25 *---------------------------------------------------------------*/
26 26
27 void WebRtcIlbcfix_Smooth( 27 void WebRtcIlbcfix_Smooth(
28 int16_t *odata, /* (o) smoothed output */ 28 int16_t *odata, /* (o) smoothed output */
29 int16_t *current, /* (i) the un enhanced residual for 29 int16_t *current, /* (i) the un enhanced residual for
30 this block */ 30 this block */
31 int16_t *surround /* (i) The approximation from the 31 int16_t *surround /* (i) The approximation from the
32 surrounding sequences */ 32 surrounding sequences */
33 ) { 33 ) {
34 int16_t maxtot, scale, scale1, scale2; 34 int16_t scale, scale1, scale2;
35 int16_t A, B, C, denomW16; 35 int16_t A, B, C, denomW16;
36 int32_t B_W32, denom, num; 36 int32_t B_W32, denom, num;
37 int32_t errs; 37 int32_t errs;
38 int32_t w00,w10,w11, endiff, crit; 38 int32_t w00,w10,w11, endiff, crit;
39 int32_t w00prim, w10prim, w11_div_w00; 39 int32_t w00prim, w10prim, w11_div_w00;
40 int16_t w11prim; 40 int16_t w11prim;
41 int16_t bitsw00, bitsw10, bitsw11; 41 int16_t bitsw00, bitsw10, bitsw11;
42 int32_t w11w00, w10w10, w00w00; 42 int32_t w11w00, w10w10, w00w00;
43 int16_t max1, max2; 43 uint32_t max1, max2;
44 44
45 /* compute some inner products (ensure no overflow by first calculating proper scale factor) */ 45 /* compute some inner products (ensure no overflow by first calculating proper scale factor) */
46 46
47 w00 = w10 = w11 = 0; 47 w00 = w10 = w11 = 0;
48 48
49 max1=WebRtcSpl_MaxAbsValueW16(current, ENH_BLOCKL); 49 // Calculate a right shift that will let us sum ENH_BLOCKL pairwise products
50 max2=WebRtcSpl_MaxAbsValueW16(surround, ENH_BLOCKL); 50 // of values from the two sequences without overflowing an int32_t. (The +1
51 maxtot=WEBRTC_SPL_MAX(max1, max2); 51 // in max1 and max2 are because WebRtcSpl_MaxAbsValueW16 will return 2**15 -
52 52 // 1 if the input array contains -2**15.)
53 scale=WebRtcSpl_GetSizeInBits(maxtot); 53 max1 = WebRtcSpl_MaxAbsValueW16(current, ENH_BLOCKL) + 1;
54 scale = (int16_t)(2 * scale) - 26; 54 max2 = WebRtcSpl_MaxAbsValueW16(surround, ENH_BLOCKL) + 1;
55 scale = (64 - 31) -
56 WebRtcSpl_CountLeadingZeros64((max1 * max2) * (uint64_t)ENH_BLOCKL);
tlegrand-webrtc 2016/05/26 12:18:21 I think you need to keep the "max 26 bits" not to
kwiberg-webrtc 2016/05/26 13:52:10 No, this piece of code works mostly the same as th
55 scale=WEBRTC_SPL_MAX(0, scale); 57 scale=WEBRTC_SPL_MAX(0, scale);
56 58
57 w00=WebRtcSpl_DotProductWithScale(current,current,ENH_BLOCKL,scale); 59 w00=WebRtcSpl_DotProductWithScale(current,current,ENH_BLOCKL,scale);
58 w11=WebRtcSpl_DotProductWithScale(surround,surround,ENH_BLOCKL,scale); 60 w11=WebRtcSpl_DotProductWithScale(surround,surround,ENH_BLOCKL,scale);
59 w10=WebRtcSpl_DotProductWithScale(surround,current,ENH_BLOCKL,scale); 61 w10=WebRtcSpl_DotProductWithScale(surround,current,ENH_BLOCKL,scale);
60 62
61 if (w00<0) w00 = WEBRTC_SPL_WORD32_MAX; 63 if (w00<0) w00 = WEBRTC_SPL_WORD32_MAX;
62 if (w11<0) w11 = WEBRTC_SPL_WORD32_MAX; 64 if (w11<0) w11 = WEBRTC_SPL_WORD32_MAX;
63 65
64 /* Rescale w00 and w11 to w00prim and w11prim, so that w00prim/w11prim 66 /* Rescale w00 and w11 to w00prim and w11prim, so that w00prim/w11prim
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 200 }
199 201
200 /* create smoothed sequence */ 202 /* create smoothed sequence */
201 203
202 WebRtcSpl_ScaleAndAddVectors(surround, A, 9, 204 WebRtcSpl_ScaleAndAddVectors(surround, A, 9,
203 current, B, 14, 205 current, B, 14,
204 odata, ENH_BLOCKL); 206 odata, ENH_BLOCKL);
205 } 207 }
206 return; 208 return;
207 } 209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698