Bug 1194085 - Abort frame parsing if no valid audio stream is found. r=jya
authorEugen Sawin <esawin@me73.com>
Fri, 14 Aug 2015 17:18:46 +0200
changeset 258287 f195230a7c5da263c0d5dbcce7dc8b31380c728f
parent 258286 2fc32f9ae54daaea040fe17d1c0ac453f2519c89
child 258288 75ba313634f34e4b5e7fd9e5e6862680c1f69ddd
push id29249
push userryanvm@gmail.com
push dateWed, 19 Aug 2015 11:17:27 +0000
treeherdermozilla-central@706b23a03d1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1194085
milestone43.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 1194085 - Abort frame parsing if no valid audio stream is found. r=jya
dom/media/MP3Demuxer.cpp
--- a/dom/media/MP3Demuxer.cpp
+++ b/dom/media/MP3Demuxer.cpp
@@ -375,31 +375,37 @@ MP3TrackDemuxer::Duration(int64_t aNumFr
 
   const double usPerFrame = USECS_PER_S * mSamplesPerFrame / mSamplesPerSecond;
   return TimeUnit::FromMicroseconds(aNumFrames * usPerFrame);
 }
 
 MediaByteRange
 MP3TrackDemuxer::FindNextFrame() {
   static const int BUFFER_SIZE = 4096;
+  static const int MAX_SKIPPED_BYTES = 10 * BUFFER_SIZE;
 
   MP3DEMUXER_LOGV("FindNext() Begin mOffset=%" PRIu64 " mNumParsedFrames=%" PRIu64
               " mFrameIndex=%" PRId64
               " mTotalFrameLen=%" PRIu64 " mSamplesPerFrame=%d mSamplesPerSecond=%d "
               "mChannels=%d",
               mOffset, mNumParsedFrames, mFrameIndex, mTotalFrameLen, mSamplesPerFrame,
               mSamplesPerSecond, mChannels);
 
   uint8_t buffer[BUFFER_SIZE];
   int32_t read = 0;
   const uint8_t* frameBeg = nullptr;
   const uint8_t* bufferEnd = nullptr;
 
-  while (frameBeg == bufferEnd &&
-         (read = Read(buffer, mOffset, BUFFER_SIZE)) > 0) {
+  while (frameBeg == bufferEnd) {
+    if ((!mParser.FirstFrame().Length() &&
+         mOffset - mParser.ID3Header().Size() > MAX_SKIPPED_BYTES) ||
+        (read = Read(buffer, mOffset, BUFFER_SIZE)) == 0) {
+      // This is not a valid MPEG audio stream or we've reached EOS, give up.
+      break;
+    }
     MOZ_ASSERT(mOffset + read > mOffset);
     mOffset += read;
     bufferEnd = buffer + read;
     frameBeg = mParser.Parse(buffer, bufferEnd);
   }
 
   if (frameBeg == bufferEnd || !mParser.CurrentFrame().Length()) {
     MP3DEMUXER_LOG("FindNext() Exit frameBeg=%p bufferEnd=%p "