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

Side by Side Diff: webrtc/modules/audio_coding/neteq/expand.cc

Issue 2571483002: Fix for integer overflow in NetEq. (Closed)
Patch Set: Update to BitExactness for arm64. Created 4 years 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 &(audio_history[signal_length - kUnvoicedLpcOrder]), 668 &(audio_history[signal_length - kUnvoicedLpcOrder]),
669 sizeof(int16_t) * kUnvoicedLpcOrder); 669 sizeof(int16_t) * kUnvoicedLpcOrder);
670 memcpy(unvoiced_vector - kUnvoicedLpcOrder, 670 memcpy(unvoiced_vector - kUnvoicedLpcOrder,
671 &(audio_history[signal_length - 128 - kUnvoicedLpcOrder]), 671 &(audio_history[signal_length - 128 - kUnvoicedLpcOrder]),
672 sizeof(int16_t) * kUnvoicedLpcOrder); 672 sizeof(int16_t) * kUnvoicedLpcOrder);
673 WebRtcSpl_FilterMAFastQ12(&audio_history[signal_length - 128], 673 WebRtcSpl_FilterMAFastQ12(&audio_history[signal_length - 128],
674 unvoiced_vector, 674 unvoiced_vector,
675 parameters.ar_filter, 675 parameters.ar_filter,
676 kUnvoicedLpcOrder + 1, 676 kUnvoicedLpcOrder + 1,
677 128); 677 128);
678 int16_t unvoiced_prescale; 678 int16_t unvoiced_max_abs = WebRtcSpl_MaxAbsValueW16(unvoiced_vector, 128);
kwiberg-webrtc 2016/12/15 14:11:16 const? Also, won't the calculation break if the a
ivoc 2016/12/15 15:12:20 Wow, good catch. I added an if-statement to increa
679 if (WebRtcSpl_MaxAbsValueW16(unvoiced_vector, 128) > 4000) { 679 // The maximum value of the dot product is 2^7 * 2^(2*n) = 2^(2*n + 7), so
kwiberg-webrtc 2016/12/15 14:11:16 "is less than", since unvoiced_max_abs < 2^n. Als
ivoc 2016/12/15 15:12:20 Done.
680 unvoiced_prescale = 4; 680 // to prevent overflows we want 2n + 7 <= 31, which means we should shift by
681 } else { 681 // 2n + 7 - 31 bits, if this value is greater than zero.
682 unvoiced_prescale = 0; 682 int16_t unvoiced_prescale =
kwiberg-webrtc 2016/12/15 14:11:16 const int?
ivoc 2016/12/15 15:12:20 Due to the newly added if statement, this can no l
683 } 683 std::max(0, 2 * WebRtcSpl_GetSizeInBits(unvoiced_max_abs) - 24);
684
684 int32_t unvoiced_energy = WebRtcSpl_DotProductWithScale(unvoiced_vector, 685 int32_t unvoiced_energy = WebRtcSpl_DotProductWithScale(unvoiced_vector,
685 unvoiced_vector, 686 unvoiced_vector,
686 128, 687 128,
687 unvoiced_prescale); 688 unvoiced_prescale);
688 689
689 // Normalize |unvoiced_energy| to 28 or 29 bits to preserve sqrt() accuracy. 690 // Normalize |unvoiced_energy| to 28 or 29 bits to preserve sqrt() accuracy.
690 int16_t unvoiced_scale = WebRtcSpl_NormW32(unvoiced_energy) - 3; 691 int16_t unvoiced_scale = WebRtcSpl_NormW32(unvoiced_energy) - 3;
691 // Make sure we do an odd number of shifts since we already have 7 shifts 692 // Make sure we do an odd number of shifts since we already have 7 shifts
692 // from dividing with 128 earlier. This will make the total scale factor 693 // from dividing with 128 earlier. This will make the total scale factor
693 // even, which is suitable for the sqrt. 694 // even, which is suitable for the sqrt.
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 962 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
962 while (samples_generated < length) { 963 while (samples_generated < length) {
963 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 964 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
964 random_vector_->IncreaseSeedIncrement(seed_increment); 965 random_vector_->IncreaseSeedIncrement(seed_increment);
965 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 966 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
966 samples_generated += rand_length; 967 samples_generated += rand_length;
967 } 968 }
968 } 969 }
969 970
970 } // namespace webrtc 971 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/acm2/audio_coding_module_unittest.cc ('k') | webrtc/modules/audio_coding/neteq/neteq_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698