Bug 1033066: Never let AudioSegments underflow mDuration and cause OOM allocation r=karlt
authorRandell Jesup <rjesup@jesup.org>
Fri, 26 Sep 2014 14:13:17 -0400
changeset 207458 808aa539aad1602f3761aa487ee92a52550e0ced
parent 207457 62e308af0e0d1127a3cc65b70edb227c18920e03
child 207459 b6f6ebcd6956db006c0436839b0e9f16b95fd4e4
push id49691
push userrjesup@wgate.com
push dateFri, 26 Sep 2014 18:14:06 +0000
treeherdermozilla-inbound@808aa539aad1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1033066
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1033066: Never let AudioSegments underflow mDuration and cause OOM allocation r=karlt
content/media/AudioSegment.cpp
content/media/AudioSegment.h
--- a/content/media/AudioSegment.cpp
+++ b/content/media/AudioSegment.cpp
@@ -149,17 +149,18 @@ void AudioSegment::ResampleChunks(SpeexR
 void
 AudioSegment::WriteTo(uint64_t aID, AudioMixer& aMixer, uint32_t aOutputChannels, uint32_t aSampleRate)
 {
   nsAutoTArray<AudioDataValue,AUDIO_PROCESSING_FRAMES*GUESS_AUDIO_CHANNELS> buf;
   nsAutoTArray<const void*,GUESS_AUDIO_CHANNELS> channelData;
   // Offset in the buffer that will end up sent to the AudioStream, in samples.
   uint32_t offset = 0;
 
-  if (!GetDuration()) {
+  if (GetDuration() <= 0) {
+    MOZ_ASSERT(GetDuration() == 0);
     return;
   }
 
   uint32_t outBufferLength = GetDuration() * aOutputChannels;
   buf.SetLength(outBufferLength);
 
 
   for (ChunkIterator ci(*this); !ci.IsEnded(); ci.Next()) {
--- a/content/media/AudioSegment.h
+++ b/content/media/AudioSegment.h
@@ -81,18 +81,18 @@ void DownmixAndInterleave(const nsTArray
  * separate pointers to each channel's buffer.
  */
 struct AudioChunk {
   typedef mozilla::AudioSampleFormat SampleFormat;
 
   // Generic methods
   void SliceTo(TrackTicks aStart, TrackTicks aEnd)
   {
-    NS_ASSERTION(aStart >= 0 && aStart < aEnd && aEnd <= mDuration,
-                 "Slice out of bounds");
+    MOZ_ASSERT(aStart >= 0 && aStart < aEnd && aEnd <= mDuration,
+               "Slice out of bounds");
     if (mBuffer) {
       MOZ_ASSERT(aStart < INT32_MAX, "Can't slice beyond 32-bit sample lengths");
       for (uint32_t channel = 0; channel < mChannelData.Length(); ++channel) {
         mChannelData[channel] = AddAudioSampleOffset(mChannelData[channel],
             mBufferFormat, int32_t(aStart));
       }
     }
     mDuration = aEnd - aStart;