Bug 1314533: [MSE] P2. Reject appendBuffer if invalid data found. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 02 Nov 2016 21:39:14 +1100
changeset 348033 33c8e33b0bb013da185f6bfaeeddf3f0074c067c
parent 348032 2d85e1b19808d93ce58072b48a7fbd6bd2f525d9
child 348034 754c160ecbed3f2f34e05916e1c814b36403ac04
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1314533
milestone52.0a1
Bug 1314533: [MSE] P2. Reject appendBuffer if invalid data found. r=gerald This still requires all the ContainerParser to be updated in properly handling errors. MozReview-Commit-ID: A7gDmXSJXmc
dom/media/mediasource/TrackBuffersManager.cpp
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -631,32 +631,45 @@ TrackBuffersManager::SegmentParserLoop()
     // ignored from the start of the input buffer.
     // We do not remove bytes from our input buffer. Instead we enforce that
     // our ContainerParser is able to skip over all data that is supposed to be
     // ignored.
 
     // 4. If the append state equals WAITING_FOR_SEGMENT, then run the following
     // steps:
     if (mSourceBufferAttributes->GetAppendState() == AppendState::WAITING_FOR_SEGMENT) {
-      if (NS_SUCCEEDED(mParser->IsInitSegmentPresent(mInputBuffer))) {
+      MediaResult haveInitSegment = mParser->IsInitSegmentPresent(mInputBuffer);
+      if (NS_SUCCEEDED(haveInitSegment)) {
         SetAppendState(AppendState::PARSING_INIT_SEGMENT);
         if (mFirstInitializationSegmentReceived) {
           // This is a new initialization segment. Obsolete the old one.
           RecreateParser(false);
         }
         continue;
       }
-      if (NS_SUCCEEDED(mParser->IsMediaSegmentPresent(mInputBuffer))) {
+      MediaResult haveMediaSegment =
+        mParser->IsMediaSegmentPresent(mInputBuffer);
+      if (NS_SUCCEEDED(haveMediaSegment)) {
         SetAppendState(AppendState::PARSING_MEDIA_SEGMENT);
         mNewMediaSegmentStarted = true;
         continue;
       }
-      // We have neither an init segment nor a media segment, this is either
-      // invalid data or not enough data to detect a segment type.
-      MSE_DEBUG("Found invalid or incomplete data.");
+      // We have neither an init segment nor a media segment.
+      // Check if it was invalid data.
+      if (haveInitSegment != NS_ERROR_NOT_AVAILABLE) {
+        MSE_DEBUG("Found invalid data.");
+        RejectAppend(haveInitSegment, __func__);
+        return;
+      }
+      if (haveMediaSegment != NS_ERROR_NOT_AVAILABLE) {
+        MSE_DEBUG("Found invalid data.");
+        RejectAppend(haveMediaSegment, __func__);
+        return;
+      }
+      MSE_DEBUG("Found incomplete data.");
       NeedMoreData();
       return;
     }
 
     int64_t start, end;
     bool newData = mParser->ParseStartAndEndTimestamps(mInputBuffer, start, end);
     mProcessedInput += mInputBuffer->Length();