diff mbox series

[FFmpeg-devel] avcodec/cfhd: check that lowpass_height is >= 3 when used in vertical filter

Message ID 20200919233416.12941-1-onemda@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel] avcodec/cfhd: check that lowpass_height is >= 3 when used in vertical filter
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Paul B Mahol Sept. 19, 2020, 11:34 p.m. UTC
Also return early when encountering fatal error.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/cfhd.c | 50 ++++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c
index ea35f03869..7b4ba4c3dd 100644
--- a/libavcodec/cfhd.c
+++ b/libavcodec/cfhd.c
@@ -415,14 +415,14 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (data > 4) {
                 av_log(avctx, AV_LOG_ERROR, "Channel Count of %"PRIu16" is unsupported\n", data);
                 ret = AVERROR_PATCHWELCOME;
-                break;
+                goto end;
             }
         } else if (tag == SubbandCount) {
             av_log(avctx, AV_LOG_DEBUG, "Subband Count: %"PRIu16"\n", data);
             if (data != SUBBAND_COUNT && data != SUBBAND_COUNT_3D) {
                 av_log(avctx, AV_LOG_ERROR, "Subband Count of %"PRIu16" is unsupported\n", data);
                 ret = AVERROR_PATCHWELCOME;
-                break;
+                goto end;
             }
         } else if (tag == ChannelNumber) {
             s->channel_num = data;
@@ -430,7 +430,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (s->channel_num >= s->planes) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid channel number\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
             init_plane_defaults(s);
         } else if (tag == SubbandNumber) {
@@ -442,12 +442,12 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
                 (s->transform_type == 2 && s->level >= DWT_LEVELS_3D)) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid level\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
             if (s->subband_num > 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid subband number\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
         } else if (tag == SubbandBand) {
             av_log(avctx, AV_LOG_DEBUG, "Subband number actual %"PRIu16"\n", data);
@@ -456,7 +456,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
                 (s->transform_type == 2 && s->subband_num_actual >= SUBBAND_COUNT_3D && s->subband_num_actual != 255)) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid subband number actual\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
         } else if (tag == LowpassPrecision)
             av_log(avctx, AV_LOG_DEBUG, "Lowpass precision bits: %"PRIu16"\n", data);
@@ -471,7 +471,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (!data || data > 5) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid band encoding\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
             s->band_encoding = data;
             av_log(avctx, AV_LOG_DEBUG, "Encode Method for Subband %d : %x\n", s->subband_num_actual, data);
@@ -489,11 +489,11 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (data > 2) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid transform type\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             } else if (data == 1) {
                 av_log(avctx, AV_LOG_ERROR, "unsupported transform type\n");
                 ret = AVERROR_PATCHWELCOME;
-                break;
+                goto end;
             }
             s->transform_type = data;
             av_log(avctx, AV_LOG_DEBUG, "Transform type %"PRIu16"\n", data);
@@ -510,7 +510,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (data > bytestream2_get_bytes_left(&gb) / 4) {
                 av_log(avctx, AV_LOG_ERROR, "too many values (%d)\n", data);
                 ret = AVERROR_INVALIDDATA;
-                break;
+                goto end;
             }
             for (i = 0; i < data; i++) {
                 uint32_t offset = bytestream2_get_be32(&gb);
@@ -521,7 +521,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (data < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid highpass width\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
             s->plane[s->channel_num].band[s->level][s->subband_num].width  = data;
             s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
@@ -530,7 +530,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (data < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid highpass height\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
             s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
         } else if (tag == BandWidth) {
@@ -538,7 +538,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (data < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid highpass width2\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
             s->plane[s->channel_num].band[s->level][s->subband_num].width  = data;
             s->plane[s->channel_num].band[s->level][s->subband_num].stride = FFALIGN(data, 8);
@@ -547,7 +547,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (data < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid highpass height2\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
             s->plane[s->channel_num].band[s->level][s->subband_num].height = data;
         } else if (tag == InputFormat) {
@@ -574,7 +574,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             if (!(data == 10 || data == 12)) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid bits per channel\n");
                 ret = AVERROR(EINVAL);
-                break;
+                goto end;
             }
             avctx->bits_per_raw_sample = s->bpc = data;
         } else if (tag == EncodedFormat) {
@@ -590,7 +590,7 @@  static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             } else {
                 avpriv_report_missing_feature(avctx, "Sample format of %"PRIu16, data);
                 ret = AVERROR_PATCHWELCOME;
-                break;
+                goto end;
             }
             s->planes = data == 2 ? 4 : av_pix_fmt_count_planes(s->coded_format);
         } else if (tag == -DisplayHeight) {
@@ -904,7 +904,8 @@  finish:
             }
 
             if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
-                !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width) {
+                !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width ||
+                lowpass_height < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
                 ret = AVERROR(EINVAL);
                 goto end;
@@ -944,7 +945,8 @@  finish:
             highpass_stride = s->plane[plane].band[1][1].stride;
 
             if (lowpass_height > s->plane[plane].band[1][1].a_height || lowpass_width > s->plane[plane].band[1][1].a_width ||
-                !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width) {
+                !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width ||
+                lowpass_height < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
                 ret = AVERROR(EINVAL);
                 goto end;
@@ -982,7 +984,8 @@  finish:
             highpass_stride = s->plane[plane].band[2][1].stride;
 
             if (lowpass_height > s->plane[plane].band[2][1].a_height || lowpass_width > s->plane[plane].band[2][1].a_width ||
-                !highpass_stride || s->plane[plane].band[2][1].width > s->plane[plane].band[2][1].a_width) {
+                !highpass_stride || s->plane[plane].band[2][1].width > s->plane[plane].band[2][1].a_width ||
+                lowpass_height < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
                 ret = AVERROR(EINVAL);
                 goto end;
@@ -1068,7 +1071,8 @@  finish:
             }
 
             if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
-                !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width) {
+                !highpass_stride || s->plane[plane].band[0][1].width > s->plane[plane].band[0][1].a_width ||
+                lowpass_height < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
                 ret = AVERROR(EINVAL);
                 goto end;
@@ -1106,7 +1110,8 @@  finish:
             highpass_stride = s->plane[plane].band[1][1].stride;
 
             if (lowpass_height > s->plane[plane].band[1][1].a_height || lowpass_width > s->plane[plane].band[1][1].a_width ||
-                !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width) {
+                !highpass_stride || s->plane[plane].band[1][1].width > s->plane[plane].band[1][1].a_width ||
+                lowpass_height < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
                 ret = AVERROR(EINVAL);
                 goto end;
@@ -1158,7 +1163,8 @@  finish:
             av_log(avctx, AV_LOG_DEBUG, "temporal level %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
 
             if (lowpass_height > s->plane[plane].band[4][1].a_height || lowpass_width > s->plane[plane].band[4][1].a_width ||
-                !highpass_stride || s->plane[plane].band[4][1].width > s->plane[plane].band[4][1].a_width) {
+                !highpass_stride || s->plane[plane].band[4][1].width > s->plane[plane].band[4][1].a_width ||
+                lowpass_height < 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n");
                 ret = AVERROR(EINVAL);
                 goto end;