From 9024da84c9a4c3f4358f310d4be5df37723ec70c Mon Sep 17 00:00:00 2001 From: Henrik Lundin Date: Mon, 21 May 2018 13:41:16 +0200 Subject: [PATCH] NetEq: Fixing an overflow bug in expand.cc The overflow currently does not cause any problems, but it has been found that it can cause crashes after a refactoring that is coming in the near future. Bug: webrtc:9180 Change-Id: Ia2c4e545c062c4f8ad13cbc47b8796c6e8a4e906 Reviewed-on: https://webrtc-review.googlesource.com/77667 Reviewed-by: Ivo Creusen Commit-Queue: Henrik Lundin Cr-Commit-Position: refs/heads/master@{#23327} --- modules/audio_coding/neteq/expand.cc | 6 +++--- modules/audio_coding/neteq/neteq_unittest.cc | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/audio_coding/neteq/expand.cc b/modules/audio_coding/neteq/expand.cc index 03bcc77ff0..73e8d07e0d 100644 --- a/modules/audio_coding/neteq/expand.cc +++ b/modules/audio_coding/neteq/expand.cc @@ -743,9 +743,9 @@ void Expand::AnalyzeSignal(int16_t* random_vector) { // the division. // Shift the denominator from Q13 to Q5 before the division. The result of // the division will then be in Q20. - int temp_ratio = WebRtcSpl_DivW32W16( - (slope - 8192) << 12, - static_cast((distortion_lag * slope) >> 8)); + int16_t denom = + rtc::saturated_cast((distortion_lag * slope) >> 8); + int temp_ratio = WebRtcSpl_DivW32W16((slope - 8192) << 12, denom); if (slope > 14746) { // slope > 1.8. // Divide by 2, with proper rounding. diff --git a/modules/audio_coding/neteq/neteq_unittest.cc b/modules/audio_coding/neteq/neteq_unittest.cc index 4cd3014b38..42dbcf3536 100644 --- a/modules/audio_coding/neteq/neteq_unittest.cc +++ b/modules/audio_coding/neteq/neteq_unittest.cc @@ -502,15 +502,15 @@ TEST_F(NetEqDecodingTest, MAYBE_TestOpusBitExactness) { webrtc::test::ResourcePath("audio_coding/neteq_opus", "rtp"); const std::string output_checksum = PlatformChecksum( - "7ea28d7edf9395f4ac8e8d8dd3a9e5c620b1bf48", - "5b1e691ab1c4465c742d6d944bc71e3b1c0e4c0e", - "b096114dd8c233eaf2b0ce9802ac95af13933772", - "7ea28d7edf9395f4ac8e8d8dd3a9e5c620b1bf48", - "7ea28d7edf9395f4ac8e8d8dd3a9e5c620b1bf48"); + "e0e4063d55941792a725fde1f781ebbbe83b8165", + "b77d2f25db1e59e054160a89e7defc7bfdb12f31", + "a8a525c476a922456a35b5b13861b55cd8c9c7b8", + "e0e4063d55941792a725fde1f781ebbbe83b8165", + "e0e4063d55941792a725fde1f781ebbbe83b8165"); const std::string network_stats_checksum = PlatformChecksum("9e72233c78baf685e500dd6c94212b30a4c5f27d", - "9a37270e4242fbd31e80bb47dc5e7ab82cf2d557", + "c237d7ca04cbb1ea2e3b27a7c8963015deb985e7", "4f1e9734bc80a290faaf9d611efcb8d7802dbc4f", "9e72233c78baf685e500dd6c94212b30a4c5f27d", "9e72233c78baf685e500dd6c94212b30a4c5f27d");