Bug 1412183 - use BufferReader instead of ByteReader in mp4 index parser. r?kinetik draft
authorAlfredo.Yang <ayang@mozilla.com>
Mon, 23 Oct 2017 10:43:30 +0800
changeset 688536 b966dfde4ab516cba86b9a871be3fe1ceb8b2f99
parent 688337 d3910b7628b8066d3f30d58b17b5824b05768854
child 688537 4f9ede4864fc5a633a3c1f988e4a6455e15fff47
push id86773
push userbmo:ayang@mozilla.com
push dateMon, 30 Oct 2017 07:33:11 +0000
reviewerskinetik
bugs1412183
milestone58.0a1
Bug 1412183 - use BufferReader instead of ByteReader in mp4 index parser. r?kinetik MozReview-Commit-ID: KNfqpgzQleE
media/libstagefright/binding/Index.cpp
--- a/media/libstagefright/binding/Index.cpp
+++ b/media/libstagefright/binding/Index.cpp
@@ -1,13 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "mp4_demuxer/ByteReader.h"
+#include "mp4_demuxer/BufferReader.h"
 #include "mp4_demuxer/Index.h"
 #include "mp4_demuxer/Interval.h"
 #include "mp4_demuxer/MP4Metadata.h"
 #include "mp4_demuxer/SinfParser.h"
 #include "nsAutoPtr.h"
 #include "mozilla/RefPtr.h"
 
 #include <algorithm>
@@ -149,39 +149,45 @@ already_AddRefed<MediaRawData> SampleIte
 
     // The size comes from an 8 bit field
     AutoTArray<uint8_t, 256> cenc;
     cenc.SetLength(s->mCencRange.Length());
     if (!mIndex->mSource->ReadAt(s->mCencRange.mStart, cenc.Elements(), cenc.Length(),
                                  &bytesRead) || bytesRead != cenc.Length()) {
       return nullptr;
     }
-    ByteReader reader(cenc);
+    BufferReader reader(cenc);
     writer->mCrypto.mValid = true;
     writer->mCrypto.mIVSize = ivSize;
 
     CencSampleEncryptionInfoEntry* sampleInfo = GetSampleEncryptionEntry();
     if (sampleInfo) {
       writer->mCrypto.mKeyId.AppendElements(sampleInfo->mKeyId);
     }
 
     if (!reader.ReadArray(writer->mCrypto.mIV, ivSize)) {
       return nullptr;
     }
 
-    if (reader.CanRead16()) {
-      uint16_t count = reader.ReadU16();
+    auto res = reader.ReadU16();
+    if (res.isOk()) {
+      uint16_t count = res.unwrap();
 
       if (reader.Remaining() < count * 6) {
         return nullptr;
       }
 
       for (size_t i = 0; i < count; i++) {
-        writer->mCrypto.mPlainSizes.AppendElement(reader.ReadU16());
-        writer->mCrypto.mEncryptedSizes.AppendElement(reader.ReadU32());
+        auto res_16 = reader.ReadU16();
+        auto res_32 = reader.ReadU32();
+        if (res_16.isErr() || res_32.isErr()) {
+          return nullptr;
+        }
+        writer->mCrypto.mPlainSizes.AppendElement(res_16.unwrap());
+        writer->mCrypto.mEncryptedSizes.AppendElement(res_32.unwrap());
       }
     } else {
       // No subsample information means the entire sample is encrypted.
       writer->mCrypto.mPlainSizes.AppendElement(0);
       writer->mCrypto.mEncryptedSizes.AppendElement(sample->Size());
     }
   }