Bug 1306477 - Updates an assert in Clearkey to deal with unencrypted samples. r?cpearce
MozReview-Commit-ID: 42VfekHccjK
--- 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.