mov: Prevent segfaults on mov_write_hdlr_tag
authorLuca Barbato <lu_zero@gentoo.org>
Mon, 19 Aug 2013 15:18:23 +0000 (17:18 +0200)
committerLuca Barbato <lu_zero@gentoo.org>
Mon, 19 Aug 2013 22:22:58 +0000 (00:22 +0200)
Do not segfault when writing tracks such as tmcd by writing them down
as generic DataHandlers if not known.

libavformat/movenc.c

index 0f21ae2..b83b0c0 100644 (file)
@@ -1239,11 +1239,11 @@ static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track)
     const char *hdlr, *descr = NULL, *hdlr_type = NULL;
     int64_t pos = avio_tell(pb);
 
-    if (!track) { /* no media --> data handler */
-        hdlr      = "dhlr";
-        hdlr_type = "url ";
-        descr     = "DataHandler";
-    } else {
+    hdlr      = "dhlr";
+    hdlr_type = "url ";
+    descr     = "DataHandler";
+
+    if (track) {
         hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
         if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) {
             hdlr_type = "vide";
@@ -1258,6 +1258,17 @@ static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track)
         } else if (track->enc->codec_tag == MKTAG('r','t','p',' ')) {
             hdlr_type = "hint";
             descr     = "HintHandler";
+        } else if (track->enc->codec_tag == MKTAG('t','m','c','d')) {
+            hdlr_type = "tmcd";
+            descr = "TimeCodeHandler";
+        } else {
+            char tag_buf[32];
+            av_get_codec_tag_string(tag_buf, sizeof(tag_buf),
+                                    track->enc->codec_tag);
+
+            av_log(track->enc, AV_LOG_WARNING,
+                   "Unknown hldr_type for %s / 0x%04X, writing dummy values\n",
+                   tag_buf, track->enc->codec_tag);
         }
     }