[FFmpeg-cvslog] avformat/asfdec_f: Use dynamic allocation in asf_read_metadata() instead of a fixed size buffer

John Adlum git at videolan.org
Thu Jul 2 05:15:54 CEST 2015


ffmpeg | branch: master | John Adlum <john.adlum at nospam> | Wed Jul  1 23:46:30 2015 +0200| [59fffefdb4dd4bbec419c58e173202fd0975e527] | committer: Michael Niedermayer

avformat/asfdec_f: Use dynamic allocation in asf_read_metadata() instead of a fixed size buffer

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=59fffefdb4dd4bbec419c58e173202fd0975e527
---

 libavformat/asfdec_f.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c
index 807df4e..baa7c18 100644
--- a/libavformat/asfdec_f.c
+++ b/libavformat/asfdec_f.c
@@ -686,24 +686,29 @@ static int asf_read_metadata(AVFormatContext *s, int64_t size)
 {
     AVIOContext *pb = s->pb;
     ASFContext *asf = s->priv_data;
-    int n, stream_num, name_len, value_len;
+    int n, stream_num, name_len_utf16, name_len_utf8, value_len;
     int ret, i;
     n = avio_rl16(pb);
 
     for (i = 0; i < n; i++) {
-        char name[1024];
+        uint8_t *name;
         int value_type;
 
         avio_rl16(pb);  // lang_list_index
         stream_num = avio_rl16(pb);
-        name_len   = avio_rl16(pb);
+        name_len_utf16 = avio_rl16(pb);
         value_type = avio_rl16(pb); /* value_type */
         value_len  = avio_rl32(pb);
 
-        if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
-            avio_skip(pb, name_len - ret);
+        name_len_utf8 = 2*name_len_utf16 + 1;
+        name          = av_malloc(name_len_utf8);
+        if (!name)
+            return AVERROR(ENOMEM);
+
+        if ((ret = avio_get_str16le(pb, name_len_utf16, name, name_len_utf8)) < name_len_utf16)
+            avio_skip(pb, name_len_utf16 - ret);
         av_log(s, AV_LOG_TRACE, "%d stream %d name_len %2d type %d len %4d <%s>\n",
-                i, stream_num, name_len, value_type, value_len, name);
+                i, stream_num, name_len_utf16, value_type, value_len, name);
 
         if (!strcmp(name, "AspectRatioX")){
             int aspect_x = get_value(s->pb, value_type, 16);



More information about the ffmpeg-cvslog mailing list