]> git.sesse.net Git - ffmpeg/commitdiff
lavf/mov.c: Prevent memory leak in case of invalid metadata reads.
authorThilo Borgmann <thilo.borgmann@mail.de>
Tue, 21 Oct 2014 08:10:55 +0000 (10:10 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 21 Oct 2014 10:36:52 +0000 (12:36 +0200)
Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/mov.c

index a7ec910595669ca31c8591f760ead3a804b0e553..80549eca54f3a00bd2ade98c9871130461ea8e5d 100644 (file)
@@ -355,16 +355,16 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     }
 #endif
 
-    str_size_alloc = str_size << 1; // worst-case requirement for output string in case of utf8 coded input
-    str = av_malloc(str_size_alloc);
-    if (!str)
-        return AVERROR(ENOMEM);
-
     if (!key)
         return 0;
     if (atom.size < 0)
         return AVERROR_INVALIDDATA;
 
+    str_size_alloc = str_size << 1; // worst-case requirement for output string in case of utf8 coded input
+    str = av_malloc(str_size_alloc);
+    if (!str)
+        return AVERROR(ENOMEM);
+
     if (parse)
         parse(c, pb, str_size, key);
     else {
@@ -372,8 +372,10 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
             mov_read_mac_string(c, pb, str_size, str, str_size_alloc);
         } else {
             int ret = avio_read(pb, str, str_size);
-            if (ret != str_size)
+            if (ret != str_size) {
+                av_freep(&str);
                 return ret < 0 ? ret : AVERROR_INVALIDDATA;
+            }
             str[str_size] = 0;
         }
         c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;