Bug 1308121-Handle unrecognized content type parameter when trying to get supported capability. draft
authorKilik Kuo <kikuo@mozilla.com>
Fri, 07 Oct 2016 00:45:27 +0800
changeset 421705 c4e002d8165e1ee7b86dca8832edb70480e3cae2
parent 421441 c7d62e6d052c5d2638b08d480a720254ea09ff2d
child 533140 c3151561da890977a8463c6aa2014fd88a40a7d6
push id31566
push userkikuo@mozilla.com
push dateThu, 06 Oct 2016 16:48:11 +0000
bugs1308121
milestone52.0a1
Bug 1308121-Handle unrecognized content type parameter when trying to get supported capability. MozReview-Commit-ID: GqSjn6BjhTi
dom/media/eme/MediaKeySystemAccess.cpp
--- a/dom/media/eme/MediaKeySystemAccess.cpp
+++ b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -636,16 +636,47 @@ AllCodecsOfType(const nsTArray<GMPCodecS
   for (const GMPCodecString& codec : aCodecs) {
     if (GetCodecType(codec) != aCodecType) {
       return false;
     }
   }
   return true;
 }
 
+static bool
+IsParameterUnrecognized(const nsAString& aContentType)
+{
+  nsAutoString contentType(aContentType);
+  contentType.StripWhitespace();
+
+  nsTArray<nsString> params;
+  nsAString::const_iterator start, end, semicolon, equalSign;
+  contentType.BeginReading(start);
+  contentType.EndReading(end);
+  semicolon = start;
+  // Find any substring between ';' & '='.
+  while (semicolon != end) {
+    if (FindCharInReadable(';', semicolon, end)) {
+      equalSign = ++semicolon;
+      if (FindCharInReadable('=', equalSign, end)) {
+        params.AppendElement(Substring(semicolon, equalSign));
+        semicolon = equalSign;
+      }
+    }
+  }
+
+  for (auto param : params) {
+    if (!param.LowerCaseEqualsLiteral("codecs") &&
+        !param.LowerCaseEqualsLiteral("profiles")) {
+      return true;
+    }
+  }
+  return false;
+}
+
 // 3.1.2.3 Get Supported Capabilities for Audio/Video Type
 static Sequence<MediaKeySystemMediaCapability>
 GetSupportedCapabilities(const CodecType aCodecType,
                          mozIGeckoMediaPluginService* aGMPService,
                          const nsTArray<MediaKeySystemMediaCapability>& aRequestedCapabilities,
                          const MediaKeySystemConfiguration& aPartialConfig,
                          const KeySystemConfig& aKeySystem,
                          DecoderDoctorDiagnostics* aDiagnostics)
@@ -744,16 +775,20 @@ GetSupportedCapabilities(const CodecType
               NS_ConvertUTF16toUTF8(robustness).get());
       continue;
     }
 
     // Let parameters be the RFC 6381[RFC6381] parameters, if any, specified by
     // content type.
     // If the user agent does not recognize one or more parameters, continue to
     // the next iteration.
+    if (IsParameterUnrecognized(contentType)) {
+      continue;
+    }
+
     // Let media types be the set of codecs and codec constraints specified by
     // parameters. The case-sensitivity of string comparisons is determined by
     // the appropriate RFC or other specification.
     // (Note: codecs array is 'parameter').
 
     // If media types is empty:
     if (codecs.IsEmpty()) {
       // If container normatively implies a specific set of codecs and codec constraints: