Bug 1451681 - Handle case where crypto plain size definition didn't exist. r=cpearce a=jcristau
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 09 Apr 2018 11:39:13 +0200
changeset 785698 532e1f4200f9c9dd7f02af68e0e385e5868906d7
parent 785697 b70d5eaa79214e698a7b064b86729701d86b0740
child 785699 e6cdf63c59a494a79197fcefca78a83399244a8e
push id107301
push usermozilla@kaply.com
push dateFri, 20 Apr 2018 16:10:30 +0000
reviewerscpearce, jcristau
bugs1451681
milestone60.0
Bug 1451681 - Handle case where crypto plain size definition didn't exist. r=cpearce a=jcristau Also ensure that the MP4 demuxer can't create such sample. MozReview-Commit-ID: JANgHNiiz2H
dom/media/mp4/Index.cpp
dom/media/platforms/agnostic/bytestreams/AnnexB.cpp
--- a/dom/media/mp4/Index.cpp
+++ b/dom/media/mp4/Index.cpp
@@ -161,17 +161,17 @@ already_AddRefed<MediaRawData> SampleIte
       writer->mCrypto.mKeyId.AppendElements(sampleInfo->mKeyId);
     }
 
     if (!reader.ReadArray(writer->mCrypto.mIV, ivSize)) {
       return nullptr;
     }
 
     auto res = reader.ReadU16();
-    if (res.isOk()) {
+    if (res.isOk() && res.unwrap() > 0) {
       uint16_t count = res.unwrap();
 
       if (reader.Remaining() < count * 6) {
         return nullptr;
       }
 
       for (size_t i = 0; i < count; i++) {
         auto res_16 = reader.ReadU16();
--- a/dom/media/platforms/agnostic/bytestreams/AnnexB.cpp
+++ b/dom/media/platforms/agnostic/bytestreams/AnnexB.cpp
@@ -69,18 +69,23 @@ AnnexB::ConvertSampleToAnnexB(mozilla::M
       return Err(NS_ERROR_OUT_OF_MEMORY);
     }
 
     // Prepending the NAL with SPS/PPS will mess up the encryption subsample
     // offsets. So we need to account for the extra bytes by increasing
     // the length of the first clear data subsample. Otherwise decryption
     // will fail.
     if (aSample->mCrypto.mValid) {
-      MOZ_ASSERT(samplewriter->mCrypto.mPlainSizes.Length() > 0);
-      samplewriter->mCrypto.mPlainSizes[0] += annexB->Length();
+      if (aSample->mCrypto.mPlainSizes.Length() == 0) {
+        samplewriter->mCrypto.mPlainSizes.AppendElement(annexB->Length());
+        samplewriter->mCrypto.mEncryptedSizes.AppendElement(
+          samplewriter->Size() - annexB->Length());
+      } else {
+        samplewriter->mCrypto.mPlainSizes[0] += annexB->Length();
+      }
     }
   }
 
   return Ok();
 }
 
 already_AddRefed<mozilla::MediaByteBuffer>
 AnnexB::ConvertExtraDataToAnnexB(const mozilla::MediaByteBuffer* aExtraData)