From 1db6ef799b4ea8b5955aa2d264b6ea4f04b71cc2 Mon Sep 17 00:00:00 2001 From: Bryce Van Dyk Date: Fri, 11 Jan 2019 15:11:05 +0000 Subject: [PATCH] Bug 1487416 - Read pattern information in Sinf parser. r=jya Differential Revision: https://phabricator.services.mozilla.com/D15873 --HG-- extra : moz-landing-system : lando --- dom/media/mp4/SinfParser.cpp | 34 +++++++++++++++++++++++++++++++--- dom/media/mp4/SinfParser.h | 15 ++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/dom/media/mp4/SinfParser.cpp b/dom/media/mp4/SinfParser.cpp index 332d2e54d9f0..4ea14adaaac2 100644 --- a/dom/media/mp4/SinfParser.cpp +++ b/dom/media/mp4/SinfParser.cpp @@ -55,12 +55,40 @@ Result SinfParser::ParseTenc(Box& aBox) { return Err(NS_ERROR_FAILURE); } - MOZ_TRY(reader->ReadU32()); // flags -- ignore + uint32_t flags; + MOZ_TRY_VAR(flags, reader->ReadU32()); + uint8_t version = flags >> 24; - uint32_t isEncrypted; - MOZ_TRY_VAR(isEncrypted, reader->ReadU24()); + // Skip reserved byte + MOZ_TRY(reader->ReadU8()); + if (version >= 1) { + uint8_t pattern; + MOZ_TRY_VAR(pattern, reader->ReadU8()); + mSinf.mDefaultCryptByteBlock = pattern >> 4; + mSinf.mDefaultSkipByteBlock = pattern & 0x0f; + } else { + // Reserved if version is less than 1 + MOZ_TRY(reader->ReadU8()); + mSinf.mDefaultCryptByteBlock = 0; + mSinf.mDefaultSkipByteBlock = 0; + } + + uint8_t isEncrypted; + MOZ_TRY_VAR(isEncrypted, reader->ReadU8()); MOZ_TRY_VAR(mSinf.mDefaultIVSize, reader->ReadU8()); memcpy(mSinf.mDefaultKeyID, reader->Read(16), 16); + + if (isEncrypted && mSinf.mDefaultIVSize == 0) { + uint8_t defaultConstantIVSize; + MOZ_TRY_VAR(defaultConstantIVSize, reader->ReadU8()); + if (!mSinf.mDefaultConstantIV.SetLength(defaultConstantIVSize, + mozilla::fallible)) { + return Err(NS_ERROR_FAILURE); + } + for (uint8_t i = 0; i < defaultConstantIVSize; i++) { + MOZ_TRY_VAR(mSinf.mDefaultConstantIV.ElementAt(i), reader->ReadU8()); + } + } return Ok(); } diff --git a/dom/media/mp4/SinfParser.h b/dom/media/mp4/SinfParser.h index 813d6182379f..04e8dbf5cc35 100644 --- a/dom/media/mp4/SinfParser.h +++ b/dom/media/mp4/SinfParser.h @@ -15,16 +15,25 @@ class Box; class Sinf : public Atom { public: - Sinf() : mDefaultIVSize(0), mDefaultEncryptionType() {} + Sinf() + : mDefaultIVSize(0), + mDefaultEncryptionType(), + mDefaultCryptByteBlock(0), + mDefaultSkipByteBlock(0) {} explicit Sinf(Box& aBox); - virtual bool IsValid() override { - return !!mDefaultIVSize && !!mDefaultEncryptionType; + bool IsValid() override { + return !!mDefaultEncryptionType && // Should have an encryption scheme + (mDefaultIVSize > 0 || // and either a default IV size + mDefaultConstantIV.Length() > 0); // or a constant IV. } uint8_t mDefaultIVSize; AtomType mDefaultEncryptionType; uint8_t mDefaultKeyID[16]; + uint8_t mDefaultCryptByteBlock; + uint8_t mDefaultSkipByteBlock; + nsTArray mDefaultConstantIV; }; class SinfParser {