OSDN Git Service

MediaExtractor: ensure users to check returned value by getTrack.
authorWei Jia <wjia@google.com>
Fri, 28 Apr 2017 17:20:07 +0000 (10:20 -0700)
committerMarco Nelissen <marcone@google.com>
Thu, 14 Sep 2017 18:42:13 +0000 (11:42 -0700)
Test: fix the crash from the stream in the bug.
Bug: 37777357
Change-Id: Ia99907c396a2074a9419db9b8103a9325b290169

cmds/stagefright/stagefright.cpp
cmds/stagefright/stream.cpp
media/libstagefright/NuMediaExtractor.cpp

index a9c6eda..5f93d30 100644 (file)
@@ -1030,6 +1030,10 @@ int main(int argc, char **argv) {
                 bool haveVideo = false;
                 for (size_t i = 0; i < numTracks; ++i) {
                     sp<MediaSource> source = extractor->getTrack(i);
+                    if (source == nullptr) {
+                        fprintf(stderr, "skip NULL track %zu, track count %zu.\n", i, numTracks);
+                        continue;
+                    }
 
                     const char *mime;
                     CHECK(source->getFormat()->findCString(
@@ -1089,6 +1093,10 @@ int main(int argc, char **argv) {
                 }
 
                 mediaSource = extractor->getTrack(i);
+                if (mediaSource == nullptr) {
+                    fprintf(stderr, "skip NULL track %zu, total tracks %zu.\n", i, numTracks);
+                    return -1;
+                }
             }
         }
 
index 1a40e53..59de6d5 100644 (file)
@@ -171,7 +171,8 @@ MyConvertingStreamSource::MyConvertingStreamSource(const char *filename)
     mWriter = new MPEG2TSWriter(
             this, &MyConvertingStreamSource::WriteDataWrapper);
 
-    for (size_t i = 0; i < extractor->countTracks(); ++i) {
+    size_t numTracks = extractor->countTracks();
+    for (size_t i = 0; i < numTracks; ++i) {
         const sp<MetaData> &meta = extractor->getTrackMetaData(i);
 
         const char *mime;
@@ -181,7 +182,12 @@ MyConvertingStreamSource::MyConvertingStreamSource(const char *filename)
             continue;
         }
 
-        CHECK_EQ(mWriter->addSource(extractor->getTrack(i)), (status_t)OK);
+        sp<MediaSource> track = extractor->getTrack(i);
+        if (track == nullptr) {
+            fprintf(stderr, "skip NULL track %zu, total tracks %zu\n", i, numTracks);
+            continue;
+        }
+        CHECK_EQ(mWriter->addSource(track), (status_t)OK);
     }
 
     CHECK_EQ(mWriter->start(), (status_t)OK);
index 45c7607..7c573b9 100644 (file)
@@ -280,6 +280,10 @@ status_t NuMediaExtractor::selectTrack(size_t index) {
 
     sp<MediaSource> source = mImpl->getTrack(index);
 
+    if (source == nullptr) {
+        return ERROR_MALFORMED;
+    }
+
     status_t ret = source->start();
     if (ret != OK) {
         return ret;