diff mbox series

[FFmpeg-devel] lavc/snow: only allocate mconly_picture for decoding

Message ID 20220411084934.8477-1-anton@khirnov.net
State Accepted
Commit a4ce3706595edd9b537861f0e5447e31babf2100
Headers show
Series [FFmpeg-devel] lavc/snow: only allocate mconly_picture for decoding | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Anton Khirnov April 11, 2022, 8:49 a.m. UTC
It is not used in the encoder.
---
Does this fix the crash?
---
 libavcodec/snow.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Michael Niedermayer April 11, 2022, 7:28 p.m. UTC | #1
On Mon, Apr 11, 2022 at 10:49:34AM +0200, Anton Khirnov wrote:
> It is not used in the encoder.
> ---
> Does this fix the crash?
> ---
>  libavcodec/snow.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

This patch alone works fine

i havnt tested it in conjunction with other patches as i slightly 
lost track but 1-3 + this seem not to build or i did something stupid

thx

[...]
Anton Khirnov April 13, 2022, 10:21 a.m. UTC | #2
Quoting Michael Niedermayer (2022-04-11 21:28:10)
> On Mon, Apr 11, 2022 at 10:49:34AM +0200, Anton Khirnov wrote:
> > It is not used in the encoder.
> > ---
> > Does this fix the crash?
> > ---
> >  libavcodec/snow.c | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> This patch alone works fine
> 
> i havnt tested it in conjunction with other patches as i slightly 
> lost track but 1-3 + this seem not to build or i did something stupid

Probably conflicts with the AVCodec callback restructuring by Andreas.
This patch should not interact with the previous ones in any way, so it
should be fine if it works on its own

I also pushed the rebased versions of patches before this one, so you
can test it again if you prefer.
diff mbox series

Patch

diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index 0a500695ce..97b0448dbf 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -513,16 +513,20 @@  int ff_snow_common_init_after_header(AVCodecContext *avctx) {
     int ret, emu_buf_size;
 
     if(!s->scratchbuf) {
-        if ((ret = ff_get_buffer(s->avctx, s->mconly_picture,
-                                 AV_GET_BUFFER_FLAG_REF)) < 0)
-            return ret;
+        if (av_codec_is_decoder(avctx->codec)) {
+            if ((ret = ff_get_buffer(s->avctx, s->mconly_picture,
+                                     AV_GET_BUFFER_FLAG_REF)) < 0)
+                return ret;
+        }
+
         emu_buf_size = FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * (2 * MB_SIZE + HTAPS_MAX - 1);
         if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf,      FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE) ||
             !FF_ALLOCZ_TYPED_ARRAY(s->emu_edge_buffer, emu_buf_size))
             return AVERROR(ENOMEM);
     }
 
-    if(s->mconly_picture->format != avctx->pix_fmt) {
+    if (av_codec_is_decoder(avctx->codec) &&
+        s->mconly_picture->format != avctx->pix_fmt) {
         av_log(avctx, AV_LOG_ERROR, "pixel format changed\n");
         return AVERROR_INVALIDDATA;
     }