Bug 1282585 - Ensure content process doesn't crash if CDM crashes before MediaKeys attaches to media element or media element loads. r=jwwang
authorChris Pearce <cpearce@mozilla.com>
Wed, 29 Jun 2016 16:09:24 +1200
changeset 303215 e2525c03c65f1a0f81cd344e1aca57f22608ae42
parent 303214 ee7df8ab5bebe508e2877a691ad43b4b60568376
child 303216 50a6f462a97c39f473455a8fa496134e8a606f8a
push id79015
push usercbook@mozilla.com
push dateThu, 30 Jun 2016 10:51:07 +0000
treeherdermozilla-inbound@280e4ef4d764 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1282585
milestone50.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 1282585 - Ensure content process doesn't crash if CDM crashes before MediaKeys attaches to media element or media element loads. r=jwwang MozReview-Commit-ID: 2CpiDv6u4RP
dom/html/HTMLMediaElement.cpp
dom/media/MediaDecoder.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3200,17 +3200,23 @@ nsresult HTMLMediaElement::FinishDecoder
   for (uint32_t i = 0; i < mOutputStreams.Length(); ++i) {
     OutputMediaStream* ms = &mOutputStreams[i];
     aDecoder->AddOutputStream(ms->mStream->GetInputStream()->AsProcessedStream(),
                               ms->mFinishWhenEnded);
   }
 
 #ifdef MOZ_EME
   if (mMediaKeys) {
-    mDecoder->SetCDMProxy(mMediaKeys->GetCDMProxy());
+    if (mMediaKeys->GetCDMProxy()) {
+      mDecoder->SetCDMProxy(mMediaKeys->GetCDMProxy());
+    } else {
+      // CDM must have crashed.
+      ShutdownDecoder();
+      return NS_ERROR_FAILURE;
+    }
   }
 #endif
 
   if (mChannelLoader) {
     mChannelLoader->Done();
     mChannelLoader = nullptr;
   }
 
@@ -5491,16 +5497,22 @@ HTMLMediaElement::SetMediaKeys(mozilla::
 
     // 5.2.4 If the preceding step failed, let this object's attaching media
     // keys value be false and reject promise with a new DOMException whose
     // name is the appropriate error name.
   }
 
   // 5.3. If mediaKeys is not null, run the following steps:
   if (aMediaKeys) {
+    if (!aMediaKeys->GetCDMProxy()) {
+      promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
+        NS_LITERAL_CSTRING("CDM crashed before binding MediaKeys object to HTMLMediaElement"));
+      return promise.forget();
+    }
+
     // 5.3.1 Associate the CDM instance represented by mediaKeys with the
     // media element for decrypting media data.
     if (NS_FAILED(aMediaKeys->Bind(this))) {
       // 5.3.2 If the preceding step failed, run the following steps:
       // 5.3.2.1 Set the mediaKeys attribute to null.
       mMediaKeys = nullptr;
       // 5.3.2.2 Let this object's attaching media keys value be false.
       // 5.3.2.3 Reject promise with a new DOMException whose name is
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1708,16 +1708,17 @@ MediaDecoder::RequestCDMProxy() const
 {
   return mCDMProxyPromise;
 }
 
 void
 MediaDecoder::SetCDMProxy(CDMProxy* aProxy)
 {
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aProxy);
 
   mCDMProxyPromiseHolder.ResolveIfExists(aProxy, __func__);
 }
 #endif
 
 #ifdef MOZ_RAW
 bool
 MediaDecoder::IsRawEnabled()