[FFmpeg-cvslog] mov: Do not set stsd_count if mov_read_stsd() fails

Sean McGovern git at videolan.org
Sat Nov 11 05:29:37 EET 2017


ffmpeg | branch: master | Sean McGovern <gseanmcg at gmail.com> | Fri Jul 28 16:29:35 2017 -0400| [3050dabaa9a337ad077ec60bba664ad9861e1aa6] | committer: Sean McGovern

mov: Do not set stsd_count if mov_read_stsd() fails

Based on an FFmpeg patch by Michael Niedermayer <michael at niedermayer.cc>

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

 libavformat/mov.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 8ff60222ef..2134bd1743 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1891,24 +1891,33 @@ static int mov_read_stsd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     if (!sc->extradata)
         return AVERROR(ENOMEM);
 
-    sc->stsd_count = entries;
-    sc->extradata_size = av_mallocz_array(sc->stsd_count, sizeof(*sc->extradata_size));
-    if (!sc->extradata_size)
-        return AVERROR(ENOMEM);
+    sc->extradata_size = av_mallocz_array(entries, sizeof(*sc->extradata_size));
+    if (!sc->extradata_size) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
 
-    ret = ff_mov_read_stsd_entries(c, pb, sc->stsd_count);
+    ret = ff_mov_read_stsd_entries(c, pb, entries);
     if (ret < 0)
-        return ret;
+        goto fail;
+
+    sc->stsd_count = entries;
 
     /* Restore back the primary extradata. */
     av_free(st->codecpar->extradata);
     st->codecpar->extradata_size = sc->extradata_size[0];
     st->codecpar->extradata = av_mallocz(sc->extradata_size[0] + AV_INPUT_BUFFER_PADDING_SIZE);
-    if (!st->codecpar->extradata)
-        return AVERROR(ENOMEM);
+    if (!st->codecpar->extradata) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
     memcpy(st->codecpar->extradata, sc->extradata[0], sc->extradata_size[0]);
 
     return 0;
+fail:
+    av_freep(&sc->extradata);
+    av_freep(&sc->extradata_size);
+    return ret;
 }
 
 static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom)



More information about the ffmpeg-cvslog mailing list