diff mbox series

[FFmpeg-devel,4/4] avcodec/qsvdec: Check av_image_get_buffer_size() for failure

Message ID 20240513012011.1049366-4-michael@niedermayer.cc
State Accepted
Commit 8789c550faf4587527faf0bd4f6c6c5c64a04ae2
Headers show
Series [FFmpeg-devel,1/4] avcodec/notchlc: Check init_get_bits8() for failure | expand

Commit Message

Michael Niedermayer May 13, 2024, 1:20 a.m. UTC
Fixes: CID1477406 Improper use of negative value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/qsvdec.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Xiang, Haihao May 13, 2024, 1:47 a.m. UTC | #1
On Ma, 2024-05-13 at 03:20 +0200, Michael Niedermayer wrote:
> Fixes: CID1477406 Improper use of negative value
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/qsvdec.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index ed0bfe4c8b8..a51ddace622 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -379,9 +379,12 @@ static int qsv_decode_init_context(AVCodecContext *avctx,
> QSVContext *q, mfxVide
>  
>      q->frame_info = param->mfx.FrameInfo;
>  
> -    if (!avctx->hw_frames_ctx)
> -        q->pool = av_buffer_pool_init(av_image_get_buffer_size(avctx-
> >pix_fmt,
> -                    FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64),
> 1), av_buffer_allocz);
> +    if (!avctx->hw_frames_ctx) {
> +        ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->width,
> 128), FFALIGN(avctx->height, 64), 1);
> +        if (ret < 0)
> +            return ret;
> +        q->pool = av_buffer_pool_init(ret, av_buffer_allocz);
> +    }
>      return 0;
>  }
>  

LGTM, thx

- Haihao
Michael Niedermayer May 19, 2024, 7:50 p.m. UTC | #2
On Mon, May 13, 2024 at 01:47:36AM +0000, Xiang, Haihao wrote:
> On Ma, 2024-05-13 at 03:20 +0200, Michael Niedermayer wrote:
> > Fixes: CID1477406 Improper use of negative value
> > 
> > Sponsored-by: Sovereign Tech Fund
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/qsvdec.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> > index ed0bfe4c8b8..a51ddace622 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -379,9 +379,12 @@ static int qsv_decode_init_context(AVCodecContext *avctx,
> > QSVContext *q, mfxVide
> >  
> >      q->frame_info = param->mfx.FrameInfo;
> >  
> > -    if (!avctx->hw_frames_ctx)
> > -        q->pool = av_buffer_pool_init(av_image_get_buffer_size(avctx-
> > >pix_fmt,
> > -                    FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64),
> > 1), av_buffer_allocz);
> > +    if (!avctx->hw_frames_ctx) {
> > +        ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->width,
> > 128), FFALIGN(avctx->height, 64), 1);
> > +        if (ret < 0)
> > +            return ret;
> > +        q->pool = av_buffer_pool_init(ret, av_buffer_allocz);
> > +    }
> >      return 0;
> >  }
> >  
> 
> LGTM, thx

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index ed0bfe4c8b8..a51ddace622 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -379,9 +379,12 @@  static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVide
 
     q->frame_info = param->mfx.FrameInfo;
 
-    if (!avctx->hw_frames_ctx)
-        q->pool = av_buffer_pool_init(av_image_get_buffer_size(avctx->pix_fmt,
-                    FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64), 1), av_buffer_allocz);
+    if (!avctx->hw_frames_ctx) {
+        ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64), 1);
+        if (ret < 0)
+            return ret;
+        q->pool = av_buffer_pool_init(ret, av_buffer_allocz);
+    }
     return 0;
 }