Bug 1306477 - Updates an assert in Clearkey to deal with unencrypted samples. r?cpearce draft
authorJay Harris <jharris@mozilla.com>
Wed, 08 Feb 2017 12:18:13 +1300
changeset 483300 8d6189577ef2aa834cdd354a56ab9e5d0792ef27
parent 483299 fa5c430fa0b2ca7249591e612be8b3ed125c5ae3
child 483301 dad44ac7e46e832aabbfa824d29c785ef7a2a729
push id45277
push userbmo:jharris@mozilla.com
push dateTue, 14 Feb 2017 02:59:42 +0000
reviewerscpearce
bugs1306477
milestone54.0a1
Bug 1306477 - Updates an assert in Clearkey to deal with unencrypted samples. r?cpearce MozReview-Commit-ID: 42VfekHccjK
media/gmp-clearkey/0.1/ClearKeyDecryptionManager.cpp
--- a/media/gmp-clearkey/0.1/ClearKeyDecryptionManager.cpp
+++ b/media/gmp-clearkey/0.1/ClearKeyDecryptionManager.cpp
@@ -16,19 +16,25 @@
 
 #include "ClearKeyDecryptionManager.h"
 
 #include "psshparser/PsshParser.h"
 
 #include <assert.h>
 #include <string.h>
 #include <vector>
+#include <algorithm>
 
 using namespace cdm;
 
+bool AllZero(const std::vector<uint32_t>& aBytes)
+{
+  return all_of(aBytes.begin(), aBytes.end(), [](uint32_t b) { return b == 0; });
+}
+
 class ClearKeyDecryptor : public RefCounted
 {
 public:
   ClearKeyDecryptor();
 
   void InitKey(const Key& aKey);
   bool HasKey() const { return !!mKey.size(); }
 
@@ -221,17 +227,23 @@ ClearKeyDecryptor::Decrypt(uint8_t* aBuf
       iter += cipherBytes;
     }
 
     tmp.resize((size_t)(iter - &tmp[0]));
   } else {
     memcpy(&tmp[0], aBuffer, aBufferSize);
   }
 
-  assert(aMetadata.mIV.size() == 8 || aMetadata.mIV.size() == 16);
+  // It is possible that we could be passed an unencrypted sample, if all
+  // encrypted sample lengths are zero, and in this case, a zero length
+  // IV is allowed.
+  assert(aMetadata.mIV.size() == 8 \
+         || aMetadata.mIV.size() == 16 \
+         || (aMetadata.mIV.size() == 0 && AllZero(aMetadata.mCipherBytes)));
+
   std::vector<uint8_t> iv(aMetadata.mIV);
   iv.insert(iv.end(), CENC_KEY_LEN - aMetadata.mIV.size(), 0);
 
   ClearKeyUtils::DecryptAES(mKey, tmp, iv);
 
   if (aMetadata.NumSubsamples()) {
     // Take the decrypted buffer, split up into subsamples, and insert those
     // subsamples back into their original position in the original buffer.