diff mbox series

[FFmpeg-devel,3/3] lavfi/dnn: check the return value from sws_getContext

Message ID 1607507590-19938-3-git-send-email-mypopydev@gmail.com
State Accepted
Commit 0320dab265ef880b5b07cac1f9ebaa3fb5417f6a
Headers show
Series [FFmpeg-devel,1/3] tests/audiomatch: add free to make static analysis tools happy | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate warning Make fate failed

Commit Message

Jun Zhao Dec. 9, 2020, 9:53 a.m. UTC
From: Jun Zhao <barryjzhao@tencent.com>

sws_getContext may be return NULL, and it's will be dereferenced,
so add the check.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
 libavfilter/dnn/dnn_io_proc.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Guo, Yejun Dec. 12, 2020, 11:20 a.m. UTC | #1
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Jun
> Zhao
> Sent: 2020年12月9日 17:53
> To: ffmpeg-devel@ffmpeg.org
> Cc: Jun Zhao <barryjzhao@tencent.com>
> Subject: [FFmpeg-devel] [PATCH 3/3] lavfi/dnn: check the return value from
> sws_getContext
> 
> From: Jun Zhao <barryjzhao@tencent.com>
> 
> sws_getContext may be return NULL, and it's will be dereferenced, so add the
> check.
> 
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
>  libavfilter/dnn/dnn_io_proc.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/libavfilter/dnn/dnn_io_proc.c b/libavfilter/dnn/dnn_io_proc.c index
> db13d7f..c9b49be 100644
> --- a/libavfilter/dnn/dnn_io_proc.c
> +++ b/libavfilter/dnn/dnn_io_proc.c
> @@ -41,6 +41,13 @@ DNNReturnType proc_from_dnn_to_frame(AVFrame
> *frame, DNNData *output, void *log_
>                                   frame->height,
>                                   AV_PIX_FMT_GRAY8,
>                                   0, NULL, NULL, NULL);
> +        if (!sws_ctx) {
> +            av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale
> context for the conversion "
> +                "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
> +                av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),
> frame->width * 3, frame->height,
> +                av_get_pix_fmt_name(AV_PIX_FMT_GRAY8),
> frame->width * 3, frame->height);
> +            return DNN_ERROR;
> +        }
>          sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t
> *)output->data, 0, 0, 0},
>                             (const int[4]){frame->width * 3 * sizeof(float),
> 0, 0, 0}, 0, frame->height,
>                             (uint8_t * const*)frame->data,
> frame->linesize); @@ -64,6 +71,13 @@ DNNReturnType
> proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_
>                                   frame->height,
>                                   AV_PIX_FMT_GRAY8,
>                                   0, NULL, NULL, NULL);
> +        if (!sws_ctx) {
> +            av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale
> context for the conversion "
> +                "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
> +                av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),
> frame->width, frame->height,
> +                av_get_pix_fmt_name(AV_PIX_FMT_GRAY8),
> frame->width, frame->height);
> +            return DNN_ERROR;
> +        }
>          sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t
> *)output->data, 0, 0, 0},
>                             (const int[4]){frame->width * sizeof(float), 0, 0,
> 0}, 0, frame->height,
>                             (uint8_t * const*)frame->data,
> frame->linesize); @@ -97,6 +111,13 @@ DNNReturnType
> proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_c
>                                   frame->height,
>                                   AV_PIX_FMT_GRAYF32,
>                                   0, NULL, NULL, NULL);
> +        if (!sws_ctx) {
> +            av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale
> context for the conversion "
> +                "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
> +                av_get_pix_fmt_name(AV_PIX_FMT_GRAY8),
> frame->width * 3, frame->height,
> +
> av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width * 3,
> frame->height);
> +            return DNN_ERROR;
> +        }
>          sws_scale(sws_ctx, (const uint8_t **)frame->data,
>                             frame->linesize, 0, frame->height,
>                             (uint8_t * const*)(&input->data), @@ -121,6
> +142,13 @@ DNNReturnType proc_from_frame_to_dnn(AVFrame *frame,
> DNNData *input, void *log_c
>                                   frame->height,
>                                   AV_PIX_FMT_GRAYF32,
>                                   0, NULL, NULL, NULL);
> +        if (!sws_ctx) {
> +            av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale
> context for the conversion "
> +                "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
> +                av_get_pix_fmt_name(AV_PIX_FMT_GRAY8),
> frame->width, frame->height,
> +
> av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width, frame->height);
> +            return DNN_ERROR;
> +        }
>          sws_scale(sws_ctx, (const uint8_t **)frame->data,
>                             frame->linesize, 0, frame->height,
>                             (uint8_t * const*)(&input->data),
> --
the two patches look good to me, will push soon, thanks.
diff mbox series

Patch

diff --git a/libavfilter/dnn/dnn_io_proc.c b/libavfilter/dnn/dnn_io_proc.c
index db13d7f..c9b49be 100644
--- a/libavfilter/dnn/dnn_io_proc.c
+++ b/libavfilter/dnn/dnn_io_proc.c
@@ -41,6 +41,13 @@  DNNReturnType proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_
                                  frame->height,
                                  AV_PIX_FMT_GRAY8,
                                  0, NULL, NULL, NULL);
+        if (!sws_ctx) {
+            av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale context for the conversion "
+                "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
+                av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width * 3, frame->height,
+                av_get_pix_fmt_name(AV_PIX_FMT_GRAY8),   frame->width * 3, frame->height);
+            return DNN_ERROR;
+        }
         sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0},
                            (const int[4]){frame->width * 3 * sizeof(float), 0, 0, 0}, 0, frame->height,
                            (uint8_t * const*)frame->data, frame->linesize);
@@ -64,6 +71,13 @@  DNNReturnType proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_
                                  frame->height,
                                  AV_PIX_FMT_GRAY8,
                                  0, NULL, NULL, NULL);
+        if (!sws_ctx) {
+            av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale context for the conversion "
+                "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
+                av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width, frame->height,
+                av_get_pix_fmt_name(AV_PIX_FMT_GRAY8),   frame->width, frame->height);
+            return DNN_ERROR;
+        }
         sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0},
                            (const int[4]){frame->width * sizeof(float), 0, 0, 0}, 0, frame->height,
                            (uint8_t * const*)frame->data, frame->linesize);
@@ -97,6 +111,13 @@  DNNReturnType proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_c
                                  frame->height,
                                  AV_PIX_FMT_GRAYF32,
                                  0, NULL, NULL, NULL);
+        if (!sws_ctx) {
+            av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale context for the conversion "
+                "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
+                av_get_pix_fmt_name(AV_PIX_FMT_GRAY8),  frame->width * 3, frame->height,
+                av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width * 3, frame->height);
+            return DNN_ERROR;
+        }
         sws_scale(sws_ctx, (const uint8_t **)frame->data,
                            frame->linesize, 0, frame->height,
                            (uint8_t * const*)(&input->data),
@@ -121,6 +142,13 @@  DNNReturnType proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_c
                                  frame->height,
                                  AV_PIX_FMT_GRAYF32,
                                  0, NULL, NULL, NULL);
+        if (!sws_ctx) {
+            av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale context for the conversion "
+                "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
+                av_get_pix_fmt_name(AV_PIX_FMT_GRAY8),  frame->width, frame->height,
+                av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width, frame->height);
+            return DNN_ERROR;
+        }
         sws_scale(sws_ctx, (const uint8_t **)frame->data,
                            frame->linesize, 0, frame->height,
                            (uint8_t * const*)(&input->data),