[FFmpeg-devel] [PATCH 1/2] avformat/apetag: ensure the binary tag is valid before allocating a stream for it

James Almer jamrial at gmail.com
Fri Apr 2 02:27:36 EEST 2021


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/apetag.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavformat/apetag.c b/libavformat/apetag.c
index 6f82fbe202..5a8144a27c 100644
--- a/libavformat/apetag.c
+++ b/libavformat/apetag.c
@@ -63,9 +63,7 @@ static int ape_tag_read_field(AVFormatContext *s)
         uint8_t filename[1024];
         enum AVCodecID id;
         int ret;
-        AVStream *st = avformat_new_stream(s, NULL);
-        if (!st)
-            return AVERROR(ENOMEM);
+        AVStream *st = NULL;
 
         ret = avio_get_str(pb, size, filename, sizeof(filename));
         if (ret < 0)
@@ -76,20 +74,23 @@ static int ape_tag_read_field(AVFormatContext *s)
         }
         size -= ret;
 
-        av_dict_set(&st->metadata, key, filename, 0);
-
         if ((id = ff_guess_image2_codec(filename)) != AV_CODEC_ID_NONE) {
-            int ret = ff_add_attached_pic(s, st, s->pb, NULL, size);
+            ret = ff_add_attached_pic(s, NULL, s->pb, NULL, size);
             if (ret < 0) {
                 av_log(s, AV_LOG_ERROR, "Error reading cover art.\n");
                 return ret;
             }
+            st = s->streams[s->nb_streams - 1];
             st->codecpar->codec_id   = id;
         } else {
+            st = avformat_new_stream(s, NULL);
+            if (!st)
+                return AVERROR(ENOMEM);
             if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
                 return ret;
             st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT;
         }
+        av_dict_set(&st->metadata, key, filename, 0);
     } else {
         value = av_malloc(size+1);
         if (!value)
-- 
2.31.0



More information about the ffmpeg-devel mailing list