Bug 1033066 - Never let AudioSegments underflow mDuration and cause OOM allocation. r=karlt, a=sledru
--- 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;