Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 01/13] avcodec/mpegvideo_enc: Fix abort on allocation errors
@ 2023-10-06  2:38 Andreas Rheinhardt
  2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 02/13] avcodec/mpegvideo_enc: Remove always-false checks Andreas Rheinhardt
                   ` (11 more replies)
  0 siblings, 12 replies; 19+ messages in thread
From: Andreas Rheinhardt @ 2023-10-06  2:38 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

mpegvideo_enc uses a fixed-size array of Pictures; a slot is
considered taken if the Picture's AVFrame is set.
When an error happens after a slot has been taken, this Picture
has typically not been reset and is therefore not usable for
future requests. The code aborts when one runs out of slots
and this can happen in case of allocation failures.
Fix this by always unreferencing a Picture in case of errors.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpegvideo_enc.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 5bf4b06a11..6cd9d89e1b 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1223,8 +1223,10 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
             }
         }
         ret = av_frame_copy_props(pic->f, pic_arg);
-        if (ret < 0)
+        if (ret < 0) {
+            ff_mpeg_unref_picture(s->avctx, pic);
             return ret;
+        }
 
         pic->display_picture_number = display_picture_number;
         pic->f->pts = pts; // we set this here to avoid modifying pic_arg
@@ -1535,8 +1537,10 @@ static int select_input_picture(MpegEncContext *s)
                 }
             } else if (s->b_frame_strategy == 2) {
                 b_frames = estimate_best_b_count(s);
-                if (b_frames < 0)
+                if (b_frames < 0) {
+                    ff_mpeg_unref_picture(s->avctx, s->input_picture[0]);
                     return b_frames;
+                }
             }
 
             emms_c();
@@ -1591,7 +1595,7 @@ no_output_pic:
 
         if ((ret = av_frame_ref(s->new_picture,
                                 s->reordered_input_picture[0]->f)))
-            return ret;
+            goto fail;
 
         if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) {
             // input is a shared pix, so we can't modify it -> allocate a new
@@ -1604,13 +1608,15 @@ no_output_pic:
             pic = &s->picture[i];
 
             pic->reference = s->reordered_input_picture[0]->reference;
-            if (alloc_picture(s, pic, 0) < 0) {
-                return -1;
-            }
+            ret = alloc_picture(s, pic, 0);
+            if (ret < 0)
+                goto fail;
 
             ret = av_frame_copy_props(pic->f, s->reordered_input_picture[0]->f);
-            if (ret < 0)
-                return ret;
+            if (ret < 0) {
+                ff_mpeg_unref_picture(s->avctx, pic);
+                goto fail;
+            }
             pic->coded_picture_number = s->reordered_input_picture[0]->coded_picture_number;
             pic->display_picture_number = s->reordered_input_picture[0]->display_picture_number;
 
@@ -1631,6 +1637,9 @@ no_output_pic:
 
     }
     return 0;
+fail:
+    ff_mpeg_unref_picture(s->avctx, s->reordered_input_picture[0]);
+    return ret;
 }
 
 static void frame_end(MpegEncContext *s)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2023-10-09 17:18 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06  2:38 [FFmpeg-devel] [PATCH 01/13] avcodec/mpegvideo_enc: Fix abort on allocation errors Andreas Rheinhardt
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 02/13] avcodec/mpegvideo_enc: Remove always-false checks Andreas Rheinhardt
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 03/13] avcodec/mpegvideo_enc: Reindentation Andreas Rheinhardt
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 04/13] avcodec/mpegvideo_enc: Don't pretend input to be non-refcounted Andreas Rheinhardt
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 05/13] avcodec/mpegvideo_enc: Don't reget known values Andreas Rheinhardt
2023-10-08 16:51   ` Michael Niedermayer
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 06/13] avcodec/mpegvideo_enc: Don't overallocate arrays Andreas Rheinhardt
2023-10-07 16:33   ` Michael Niedermayer
2023-10-07 17:28     ` Andreas Rheinhardt
2023-10-09 12:30       ` Andreas Rheinhardt
2023-10-09 17:17         ` Michael Niedermayer
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 07/13] avcodec/mpegvideo_enc: Don't set write-only properties Andreas Rheinhardt
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 08/13] avcodec/mpegvideo_enc: Remove dead block Andreas Rheinhardt
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 09/13] avcodec/mpegvideo_enc: Don't allocate buffers unnecessarily Andreas Rheinhardt
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 10/13] avcodec/mpegvideo_enc: Don't call av_frame_copy_props() unnecessarily Andreas Rheinhardt
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 11/13] avcodec/mpegpicture: Move caller-specific parts of function to callers Andreas Rheinhardt
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 12/13] avcodec/mpeg(picture|video_dec): Move comment to more appropriate place Andreas Rheinhardt
2023-10-08 16:48   ` Michael Niedermayer
2023-10-06  2:46 ` [FFmpeg-devel] [PATCH 13/13] avcodec/vdpau_vc1: Fix indentation Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git