Bug 1191281 - Increase strictness of ID3 header detection. r=ehoogeveen
authorEugen Sawin <esawin@me73.com>
Tue, 04 Aug 2015 21:42:14 +0200
changeset 287983 84f78a49e2d7a098810efdbff04e331588207e5a
parent 287982 7ce747f01b726348dbe01ab143146acbd4ecdd88
child 288001 9801f91760d99bbedb99b3346c8aeb57db68c93a
child 288084 02f399ce296dca053566537ef058270b539bae03
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehoogeveen
bugs1191281
milestone42.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 1191281 - Increase strictness of ID3 header detection. r=ehoogeveen
dom/media/MP3Demuxer.cpp
--- a/dom/media/MP3Demuxer.cpp
+++ b/dom/media/MP3Demuxer.cpp
@@ -941,16 +941,19 @@ static const int FLAGS_LEN = 1;
 static const int SIZE_LEN = 4;
 
 static const int ID_END = ID_LEN;
 static const int VERSION_END = ID_END + VERSION_LEN;
 static const int FLAGS_END = VERSION_END + FLAGS_LEN;
 static const int SIZE_END = FLAGS_END + SIZE_LEN;
 
 static const uint8_t ID[ID_LEN] = {'I', 'D', '3'};
+
+static const uint8_t MIN_MAJOR_VER = 2;
+static const uint8_t MAX_MAJOR_VER = 4;
 } // namespace id3_header
 
 const uint8_t*
 ID3Parser::Parse(const uint8_t* aBeg, const uint8_t* aEnd) {
   if (!aBeg || !aEnd || aBeg >= aEnd) {
     return aEnd;
   }
 
@@ -1020,27 +1023,30 @@ ID3Parser::ID3Header::ParseNext(uint8_t 
 }
 
 bool
 ID3Parser::ID3Header::IsValid(int aPos) const {
   if (IsValid()) {
     return true;
   }
   const uint8_t c = mRaw[aPos];
-  if (aPos < id3_header::ID_END) {
-    return id3_header::ID[aPos] == c;
-  }
-  if (aPos < id3_header::VERSION_END) {
-    return c < 0xFF;
-  }
-  if (aPos < id3_header::FLAGS_END) {
-    return true;
-  }
-  if (aPos < id3_header::SIZE_END) {
-    return c < 0x80;
+  switch (aPos) {
+    case 0: case 1: case 2:
+      // Expecting "ID3".
+      return id3_header::ID[aPos] == c;
+    case 3:
+      return MajorVersion() >= id3_header::MIN_MAJOR_VER &&
+             MajorVersion() <= id3_header::MAX_MAJOR_VER;
+    case 4:
+      return MinorVersion() < 0xFF;
+    case 5:
+      // Validate flags for supported versions, see bug 949036.
+      return ((0xFF >> MajorVersion()) & c) == 0;
+    case 6: case 7: case 8: case 9:
+      return c < 0x80;
   }
   return true;
 }
 
 bool
 ID3Parser::ID3Header::IsValid() const {
   return mPos >= SIZE;
 }