Backed out changeset 2c7d3f3cb9e8 (bug 1336271) on request for possible memory issues
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Fri, 05 May 2017 09:04:09 +0200
changeset 356592 4fa8134024ea8ebc35a20fbd9406f00a448b3ed3
parent 356591 a38eaf316e46aa6aea5d3d2bad8c90c112afcbd8
child 356593 9316a48f009b758bc1f0fb76093c2cc9916eb5dd
push id31767
push usercbook@mozilla.com
push dateFri, 05 May 2017 13:15:58 +0000
treeherdermozilla-central@8872ad4d52b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1336271
milestone55.0a1
backs out2c7d3f3cb9e8ab7842f344b50fafb89d73ddfaec
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
Backed out changeset 2c7d3f3cb9e8 (bug 1336271) on request for possible memory issues
media/libstagefright/binding/MoofParser.cpp
media/libstagefright/binding/include/mp4_demuxer/MoofParser.h
--- a/media/libstagefright/binding/MoofParser.cpp
+++ b/media/libstagefright/binding/MoofParser.cpp
@@ -143,64 +143,81 @@ MoofParser::BlockingReadNextMoof()
       byteRanges += MediaByteRange(mOffset, box.Range().mEnd);
       return RebuildFragmentedIndex(context);
     }
   }
   return false;
 }
 
 void
-MoofParser::ScanForMetadata(mozilla::MediaByteRange& aMoov)
+MoofParser::ScanForMetadata(mozilla::MediaByteRange& aFtyp,
+                            mozilla::MediaByteRange& aMoov)
 {
   int64_t length = std::numeric_limits<int64_t>::max();
   mSource->Length(&length);
   MediaByteRangeSet byteRanges;
   byteRanges += MediaByteRange(0, length);
   RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
 
-  mozilla::MediaByteRange initRange;
   BoxContext context(stream, byteRanges);
   for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
-    initRange = initRange.Span(box.Range());
+    if (box.IsType("ftyp")) {
+      aFtyp = box.Range();
+      continue;
+    }
     if (box.IsType("moov")) {
-      // mInitRange is from stream start position to end of moov.
-      mInitRange = aMoov = initRange;
-      return;
+      aMoov = box.Range();
+      break;
     }
   }
+  mInitRange = aFtyp.Span(aMoov);
 }
 
 bool
 MoofParser::HasMetadata()
 {
+  MediaByteRange ftyp;
   MediaByteRange moov;
-  ScanForMetadata(moov);
-  return !!moov.Length();
+  ScanForMetadata(ftyp, moov);
+  return !!ftyp.Length() && !!moov.Length();
 }
 
 already_AddRefed<mozilla::MediaByteBuffer>
 MoofParser::Metadata()
 {
+  MediaByteRange ftyp;
   MediaByteRange moov;
-  ScanForMetadata(moov);
+  ScanForMetadata(ftyp, moov);
+  CheckedInt<MediaByteBuffer::size_type> ftypLength = ftyp.Length();
   CheckedInt<MediaByteBuffer::size_type> moovLength = moov.Length();
-  if (!moovLength.isValid() || !moovLength.value()) {
-    // No moov, or they cannot be used as array size.
+  if (!ftypLength.isValid() || !moovLength.isValid()
+      || !ftypLength.value() || !moovLength.value()) {
+    // No ftyp or moov, or they cannot be used as array size.
+    return nullptr;
+  }
+  CheckedInt<MediaByteBuffer::size_type> totalLength = ftypLength + moovLength;
+  if (!totalLength.isValid()) {
+    // Addition overflow, or sum cannot be used as array size.
     return nullptr;
   }
   RefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
-  if (!metadata->SetLength(moovLength.value(), fallible)) {
+  if (!metadata->SetLength(totalLength.value(), fallible)) {
     // OOM
     return nullptr;
   }
 
   RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
   size_t read;
   bool rv =
-    stream->ReadAt(moov.mStart, metadata->Elements(), moovLength.value(), &read);
+    stream->ReadAt(ftyp.mStart, metadata->Elements(), ftypLength.value(), &read);
+  if (!rv || read != ftypLength.value()) {
+    return nullptr;
+  }
+  rv =
+    stream->ReadAt(moov.mStart, metadata->Elements() + ftypLength.value(), moovLength.value(), &read);
   if (!rv || read != moovLength.value()) {
     return nullptr;
   }
   return metadata.forget();
 }
 
 Interval<Microseconds>
 MoofParser::GetCompositionRange(const MediaByteRangeSet& aByteRanges)
--- a/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h
@@ -294,17 +294,18 @@ public:
   Edts mEdts;
   Sinf mSinf;
 
   nsTArray<CencSampleEncryptionInfoEntry> mTrackSampleEncryptionInfoEntries;
   nsTArray<SampleToGroupEntry> mTrackSampleToGroupEntries;
 
   nsTArray<Moof>& Moofs() { return mMoofs; }
 private:
-  void ScanForMetadata(mozilla::MediaByteRange& aMoov);
+  void ScanForMetadata(mozilla::MediaByteRange& aFtyp,
+                       mozilla::MediaByteRange& aMoov);
   nsTArray<Moof> mMoofs;
   nsTArray<MediaByteRange> mMediaRanges;
   bool mIsAudio;
   uint64_t mLastDecodeTime;
 };
 }
 
 #endif