diff mbox series

[FFmpeg-devel,14/25] avformat/utils: Only allocate FFStream.info for input streams

Message ID AM7PR03MB666007A7EF7225DA8B4D753E8FC89@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 6e0823ab83056e1a0905c64568738b7f2fb14f4d
Headers show
Series [FFmpeg-devel,01/25] avformat/matroskadec: Fix heap-buffer overflow upon gigantic timestamps | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/configureppc warning Failed to apply patch

Commit Message

Andreas Rheinhardt Aug. 27, 2021, 2:27 p.m. UTC
This structure is only used for demuxers (mostly in
avformat_find_stream_info()), so only allocate it for them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
Yes, when demuxing this structure was freed in
avformat_find_stream_info(), but for muxers it was always kept.

 libavformat/utils.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8cbe2a0278..78bfb36cd0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4368,10 +4368,6 @@  AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
     if (!st->internal)
         goto fail;
 
-    st->internal->info = av_mallocz(sizeof(*st->internal->info));
-    if (!st->internal->info)
-        goto fail;
-
     st->codecpar = avcodec_parameters_alloc();
     if (!st->codecpar)
         goto fail;
@@ -4381,6 +4377,16 @@  AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
         goto fail;
 
     if (s->iformat) {
+        st->internal->info = av_mallocz(sizeof(*st->internal->info));
+        if (!st->internal->info)
+            goto fail;
+
+#if FF_API_R_FRAME_RATE
+        st->internal->info->last_dts      = AV_NOPTS_VALUE;
+#endif
+        st->internal->info->fps_first_dts = AV_NOPTS_VALUE;
+        st->internal->info->fps_last_dts  = AV_NOPTS_VALUE;
+
         /* default pts setting is MPEG-like */
         avpriv_set_pts_info(st, 33, 1, 90000);
         /* we set the current DTS to 0 so that formats without any timestamps
@@ -4407,12 +4413,6 @@  AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
 
     st->sample_aspect_ratio = (AVRational) { 0, 1 };
 
-#if FF_API_R_FRAME_RATE
-    st->internal->info->last_dts      = AV_NOPTS_VALUE;
-#endif
-    st->internal->info->fps_first_dts = AV_NOPTS_VALUE;
-    st->internal->info->fps_last_dts  = AV_NOPTS_VALUE;
-
     st->internal->inject_global_side_data = s->internal->inject_global_side_data;
 
     st->internal->need_context_update = 1;