Bug 1181220 - p2: Check if MIME types are valid - r=rillian
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 05 Nov 2015 19:10:00 +0100
changeset 271584 7964a5a4b0bd914d82822c9b1bb38dea19f90232
parent 271583 a5555f3b971232e9991ed4d430a3336e2321475e
child 271585 f8db80facd1a07af8e77b01cade5ea5c6b3bdae8
push id16135
push usercbook@mozilla.com
push dateMon, 09 Nov 2015 13:59:56 +0000
treeherderfx-team@5898d8162f44 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1181220
milestone45.0a1
Bug 1181220 - p2: Check if MIME types are valid - r=rillian
media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
--- a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
+++ b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
@@ -345,28 +345,32 @@ static const char *FourCC2MIME(uint32_t 
         case FOURCC('a', 'v', 'c', '1'):
         case FOURCC('a', 'v', 'c', '3'):
             return MEDIA_MIMETYPE_VIDEO_AVC;
 
         case FOURCC('V', 'P', '6', 'F'):
             return MEDIA_MIMETYPE_VIDEO_VP6;
 
         default:
-            CHECK(!"should not be here.");
+            ALOGE("Unknown MIME type %08x", fourcc);
             return NULL;
     }
 }
 
 static bool AdjustChannelsAndRate(uint32_t fourcc, uint32_t *channels, uint32_t *rate) {
-    if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_NB, FourCC2MIME(fourcc))) {
+    const char* mime = FourCC2MIME(fourcc);
+    if (!mime) {
+        return false;
+    }
+    if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_NB, mime)) {
         // AMR NB audio is always mono, 8kHz
         *channels = 1;
         *rate = 8000;
         return true;
-    } else if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_WB, FourCC2MIME(fourcc))) {
+    } else if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_WB, mime)) {
         // AMR WB audio is always mono, 16kHz
         *channels = 1;
         *rate = 16000;
         return true;
     }
     return false;
 }
 
@@ -1016,19 +1020,23 @@ status_t MPEG4Extractor::parseChunk(off6
         {
             uint32_t original_fourcc;
             if (mDataSource->readAt(data_offset, &original_fourcc, 4) < 4) {
                 return ERROR_IO;
             }
             original_fourcc = ntohl(original_fourcc);
             ALOGV("read original format: %d", original_fourcc);
             if (!mLastTrack) {
-              return ERROR_MALFORMED;
+                return ERROR_MALFORMED;
             }
-            mLastTrack->meta->setCString(kKeyMIMEType, FourCC2MIME(original_fourcc));
+            const char* mime = FourCC2MIME(original_fourcc);
+            if (!mime) {
+                return ERROR_UNSUPPORTED;
+            }
+            mLastTrack->meta->setCString(kKeyMIMEType, mime);
             uint32_t num_channels = 0;
             uint32_t sample_rate = 0;
             if (AdjustChannelsAndRate(original_fourcc, &num_channels, &sample_rate)) {
                 mLastTrack->meta->setInt32(kKeyChannelCount, num_channels);
                 mLastTrack->meta->setInt32(kKeySampleRate, sample_rate);
             }
             *offset += chunk_size;
             break;
@@ -1331,17 +1339,21 @@ status_t MPEG4Extractor::parseChunk(off6
             uint16_t sample_size = U16_AT(&buffer[18]);
             uint32_t sample_rate = U32_AT(&buffer[24]) >> 16;
 
             if (!mLastTrack) {
               return ERROR_MALFORMED;
             }
             if (chunk_type != FOURCC('e', 'n', 'c', 'a')) {
                 // if the chunk type is enca, we'll get the type from the sinf/frma box later
-                mLastTrack->meta->setCString(kKeyMIMEType, FourCC2MIME(chunk_type));
+                const char* mime = FourCC2MIME(chunk_type);
+                if (!mime) {
+                    return ERROR_UNSUPPORTED;
+                }
+                mLastTrack->meta->setCString(kKeyMIMEType, mime);
                 AdjustChannelsAndRate(chunk_type, &num_channels, &sample_rate);
             }
 
             uint64_t skip = 0;
             if (qt_version == 1) {
                 // Skip QTv1 extension
                 // uint32_t SamplesPerPacket
                 // uint32_t BytesPerPacket
@@ -1449,17 +1461,21 @@ status_t MPEG4Extractor::parseChunk(off6
             // printf("*** coding='%s' width=%d height=%d\n",
             //        chunk, width, height);
 
             if (!mLastTrack) {
               return ERROR_MALFORMED;
             }
             if (chunk_type != FOURCC('e', 'n', 'c', 'v')) {
                 // if the chunk type is encv, we'll get the type from the sinf/frma box later
-                mLastTrack->meta->setCString(kKeyMIMEType, FourCC2MIME(chunk_type));
+                const char* mime = FourCC2MIME(chunk_type);
+                if (!mime) {
+                    return ERROR_UNSUPPORTED;
+                }
+                mLastTrack->meta->setCString(kKeyMIMEType, mime);
             }
             mLastTrack->meta->setInt32(kKeyWidth, width);
             mLastTrack->meta->setInt32(kKeyHeight, height);
 
             off64_t stop_offset = *offset + chunk_size;
             *offset = data_offset + sizeof(buffer);
             while (*offset < stop_offset) {
                 status_t err = parseChunk(offset, depth + 1);