Bug 1349421 - Adjust handling of chunk duration in opus encoder. r=jesup, a=gchang
authorBryce Van Dyk <bvandyk@mozilla.com>
Thu, 30 Mar 2017 13:38:10 +1300
changeset 393363 d5a55164125fefa075ee1b6950c7b920686325f0
parent 393362 af9770cbd781d37a564b69cde16dd4abcbe714f3
child 393364 6fdfffd25064157b94f9a4e0f9a10c7634cdc564
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, gchang
bugs1349421
milestone54.0a2
Bug 1349421 - Adjust handling of chunk duration in opus encoder. r=jesup, a=gchang For very long chunks, the opus encoder could run into issues with processing. This changeset seeks to address that by using CheckedInt to prevent a potential int overflow when encountering extremely long durations. MozReview-Commit-ID: 7uLZAARLf5w
dom/media/encoder/OpusTrackEncoder.cpp
--- a/dom/media/encoder/OpusTrackEncoder.cpp
+++ b/dom/media/encoder/OpusTrackEncoder.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include "OpusTrackEncoder.h"
 #include "nsString.h"
 #include "GeckoProfiler.h"
+#include "mozilla/CheckedInt.h"
 
 #include <opus/opus.h>
 
 #undef LOG
 #ifdef MOZ_WIDGET_GONK
 #include <android/log.h>
 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "MediaEncoder", ## args);
 #else
@@ -339,18 +340,25 @@ OpusTrackEncoder::GetEncodedTrack(Encode
         frameToCopy = framesToFetch - frameCopied;
       }
 
       if (!chunk.IsNull()) {
         // Append the interleaved data to the end of pcm buffer.
         AudioTrackEncoder::InterleaveTrackData(chunk, frameToCopy, mChannels,
                                                pcm.Elements() + frameCopied * mChannels);
       } else {
+        CheckedInt<int> memsetLength = CheckedInt<int>(frameToCopy) *
+                                       mChannels *
+                                       sizeof(AudioDataValue);
+        if (!memsetLength.isValid()) {
+          LOG(LogLevel::Error, ("Error calculating length of pcm buffer!"));
+          return NS_ERROR_FAILURE;
+        }
         memset(pcm.Elements() + frameCopied * mChannels, 0,
-               frameToCopy * mChannels * sizeof(AudioDataValue));
+               memsetLength.value());
       }
 
       frameCopied += frameToCopy;
       iter.Next();
     }
 
     RefPtr<EncodedFrame> audiodata = new EncodedFrame();
     audiodata->SetFrameType(EncodedFrame::OPUS_AUDIO_FRAME);