diff mbox series

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

Message ID 20210401232738.4908-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avformat/apetag: ensure the binary tag is valid before allocating a stream for it
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer April 1, 2021, 11:27 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/apetag.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox series

Patch

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)