On Sun, 18 Aug 2013, Luca Barbato wrote:

Do not segfault when writing tracks such as tmcd by writing them down
as generic DataHandlers if not known.
---
libavformat/movenc.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index d3aa3db..6ac5a41 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1239,11 +1239,12 @@ 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 {
+    /*  no media --> data handler */
+    hdlr      = "dhlr";
+    hdlr_type = "url ";
+    descr     = "DataHandler";
+

Why is this necesasry? Since you below make sure all the fields either are set or we return without trying to use them, this hunk shouldn't be necessary as far as I can see?

+    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 +1259,18 @@ 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);
+            return 0;
        }
    }

This part looks good to me.

// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to