Bug 1314667 - Add bounds check when configuring simulcast streams; r=jesup a=dveditz
authorDan Minor <dminor@mozilla.com>
Wed, 02 Nov 2016 15:16:36 -0400
changeset 347673 f6aba4ec09af240e3688ba634b43a5d593ec8d9d
parent 347672 91bc0411b4f64a34dee35924e904ae01c96ed6e9
child 347674 5771d02d895e876ed321d5707ec984114c93e128
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)
reviewersjesup, dveditz
bugs1314667
milestone52.0a1
Bug 1314667 - Add bounds check when configuring simulcast streams; r=jesup a=dveditz The webrtc.org code has a hard coded limit on the number of simulcast streams. This adds a check to make sure we don't try to add more streams than it can support. Since the jsep code orders by decreasing resolution, if too many streams are passed in we will end up dropping the lowest resolution ones.
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -1995,17 +1995,18 @@ WebrtcVideoConduit::CodecConfigToWebRTCC
     // paranoia
     cinst.codecSpecific.H264.spsData = nullptr;
     cinst.codecSpecific.H264.spsLen = 0;
     cinst.codecSpecific.H264.ppsData = nullptr;
     cinst.codecSpecific.H264.ppsLen = 0;
   }
   // Init mSimulcastEncodings always since they hold info from setParameters.
   // TODO(bug 1210175): H264 doesn't support simulcast yet.
-  for (size_t i = 0; i < codecInfo->mSimulcastEncodings.size(); ++i) {
+  size_t numberOfSimulcastEncodings = std::min(codecInfo->mSimulcastEncodings.size(), (size_t)webrtc::kMaxSimulcastStreams);
+  for (size_t i = 0; i < numberOfSimulcastEncodings; ++i) {
     const VideoCodecConfig::SimulcastEncoding& encoding =
       codecInfo->mSimulcastEncodings[i];
     // Make sure the constraints on the whole stream are reflected.
     webrtc::SimulcastStream stream;
     memset(&stream, 0, sizeof(stream));
     stream.width = cinst.width;
     stream.height = cinst.height;
     stream.numberOfTemporalLayers = 1;
@@ -2039,20 +2040,20 @@ WebrtcVideoConduit::CodecConfigToWebRTCC
       SelectBitrates(new_width, new_height, stream.jsMaxBitrate,
                      mLastFramerateTenths,
                      stream.minBitrate,
                      stream.targetBitrate,
                      stream.maxBitrate);
     }
     // webrtc.org expects simulcast streams to be ordered by increasing
     // fidelity, our jsep code does the opposite.
-    cinst.simulcastStream[codecInfo->mSimulcastEncodings.size()-i-1] = stream;
+    cinst.simulcastStream[numberOfSimulcastEncodings-i-1] = stream;
   }
 
-  cinst.numberOfSimulcastStreams = codecInfo->mSimulcastEncodings.size();
+  cinst.numberOfSimulcastStreams = numberOfSimulcastEncodings;
 }
 
 /**
  * Perform validation on the codecConfig to be applied
  * Verifies if the codec is already applied.
  */
 MediaConduitErrorCode
 WebrtcVideoConduit::ValidateCodecConfig(const VideoCodecConfig* codecInfo,