Bug 1451681 - Handle case where crypto plain size definition didn't exist. r?cpearce
Also ensure that the MP4 demuxer can't create such sample.
MozReview-Commit-ID: JANgHNiiz2H
--- 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)