Bug 1313398: P5. Do not parse encrypted data. r?gerald
The encrypted data is nonsensical as far as the parsing of NALs is concerned.
MozReview-Commit-ID: Hm1fJf6h2S7
--- a/media/libstagefright/binding/AnnexB.cpp
+++ b/media/libstagefright/binding/AnnexB.cpp
@@ -283,17 +283,30 @@ AnnexB::ExtractExtraData(const mozilla::
ByteWriter spsw(sps);
int numSps = 0;
// PPS content
mozilla::Vector<uint8_t> pps;
ByteWriter ppsw(pps);
int numPps = 0;
int nalLenSize = ((*aSample->mExtraData)[4] & 3) + 1;
- ByteReader reader(aSample->Data(), aSample->Size());
+
+ size_t sampleSize = aSample->Size();
+ if (aSample->mCrypto.mValid) {
+ // The content is encrypted, we can only parse the non-encrypted data.
+ MOZ_ASSERT(aSample->mCrypto.mPlainSizes.Length() > 0);
+ if (aSample->mCrypto.mPlainSizes.Length() == 0 ||
+ aSample->mCrypto.mPlainSizes[0] > sampleSize) {
+ // This is invalid content.
+ return nullptr;
+ }
+ sampleSize = aSample->mCrypto.mPlainSizes[0];
+ }
+
+ ByteReader reader(aSample->Data(), sampleSize);
// Find SPS and PPS NALUs in AVCC data
while (reader.Remaining() > nalLenSize) {
uint32_t nalLen;
switch (nalLenSize) {
case 1: nalLen = reader.ReadU8(); break;
case 2: nalLen = reader.ReadU16(); break;
case 3: nalLen = reader.ReadU24(); break;