Bug 1487416 - Read pattern information in Sinf parser. r=jya
☠☠ backed out by b27229f70e01 ☠ ☠
authorBryce Van Dyk <bvandyk@mozilla.com>
Thu, 10 Jan 2019 18:37:20 +0000
changeset 510443 233aedc8b42ea145c3ed2d6238cf6a6142d15a34
parent 510442 f8cfb3571b81f4466e1263d87fd13202ab5885e6
child 510444 f7c201b7f9bcef99ab22193b1faf71dc8ff72195
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1487416
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1487416 - Read pattern information in Sinf parser. r=jya Differential Revision: https://phabricator.services.mozilla.com/D15873
dom/media/mp4/SinfParser.cpp
dom/media/mp4/SinfParser.h
--- a/dom/media/mp4/SinfParser.cpp
+++ b/dom/media/mp4/SinfParser.cpp
@@ -50,18 +50,46 @@ Result<Ok, nsresult> SinfParser::ParseSc
 
 Result<Ok, nsresult> SinfParser::ParseTenc(Box& aBox) {
   BoxReader reader(aBox);
 
   if (reader->Remaining() < 24) {
     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();
 }
 
 }  // namespace mozilla
--- a/dom/media/mp4/SinfParser.h
+++ b/dom/media/mp4/SinfParser.h
@@ -10,26 +10,35 @@
 #include "AtomType.h"
 
 namespace mozilla {
 
 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<uint8_t> mDefaultConstantIV;
 };
 
 class SinfParser {
  public:
   explicit SinfParser(Box& aBox);
 
   Sinf& GetSinf() { return mSinf; }