diff mbox series

[FFmpeg-devel] avcodec/msvideo1enc: Add check for av_malloc

Message ID 20230417023251.46560-1-jiasheng@iscas.ac.cn
State Accepted
Commit b9ba036680b4164f6e415a85877dfa659ae4dde1
Headers show
Series [FFmpeg-devel] avcodec/msvideo1enc: Add check for av_malloc | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Jiasheng Jiang April 17, 2023, 2:32 a.m. UTC
Add the check for the return value of the av_malloc in order to avoid
NULL pointer deference.

Fixes: e4be3485af ("MS Video 1 encoder")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 libavcodec/msvideo1enc.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

James Almer April 17, 2023, 2:38 a.m. UTC | #1
On 4/16/2023 11:32 PM, Jiasheng Jiang wrote:
> Add the check for the return value of the av_malloc in order to avoid
> NULL pointer deference.
> 
> Fixes: e4be3485af ("MS Video 1 encoder")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>   libavcodec/msvideo1enc.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/libavcodec/msvideo1enc.c b/libavcodec/msvideo1enc.c
> index 36cfd39a85..1fb8be8883 100644
> --- a/libavcodec/msvideo1enc.c
> +++ b/libavcodec/msvideo1enc.c
> @@ -84,6 +84,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>   
>       if(!c->prev)
>           c->prev = av_malloc(avctx->width * 3 * (avctx->height + 3));
> +    if (!c->prev)
> +        return AVERROR(ENOMEM);
>       prevptr = c->prev + avctx->width * 3 * (FFALIGN(avctx->height, 4) - 1);
>       src = (const uint16_t*)(p->data[0] + p->linesize[0]*(FFALIGN(avctx->height, 4) - 1));
>       if(c->keyint >= avctx->keyint_min)

Applied, thanks.
diff mbox series

Patch

diff --git a/libavcodec/msvideo1enc.c b/libavcodec/msvideo1enc.c
index 36cfd39a85..1fb8be8883 100644
--- a/libavcodec/msvideo1enc.c
+++ b/libavcodec/msvideo1enc.c
@@ -84,6 +84,8 @@  static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
     if(!c->prev)
         c->prev = av_malloc(avctx->width * 3 * (avctx->height + 3));
+    if (!c->prev)
+        return AVERROR(ENOMEM);
     prevptr = c->prev + avctx->width * 3 * (FFALIGN(avctx->height, 4) - 1);
     src = (const uint16_t*)(p->data[0] + p->linesize[0]*(FFALIGN(avctx->height, 4) - 1));
     if(c->keyint >= avctx->keyint_min)