From patchwork Sat Sep 19 23:34:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 22509 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B93C944A0DE for ; Sun, 20 Sep 2020 02:34:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92BB368B7B6; Sun, 20 Sep 2020 02:34:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EDC2A68B72C for ; Sun, 20 Sep 2020 02:34:33 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id w2so8657273wmi.1 for ; Sat, 19 Sep 2020 16:34:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=p8Jvf/lKOlrdJnYYTQwvQ4jk7EM8WIiBma3ZPM/hMGk=; b=qts0qL6wIBqUy0GPmCCgcuSlJsXTO0mE+KIANwQlJcGgks4WJ1Qyinx30yvu1r1OgC 8jFDlyXKzIPNtaKDIK8zNpYpyxeQ8N6bp18oJeqUCJCsMInbgJorVHQhcVI3al+C8vAf vEh+4B7hrRR74h6ZdclWYWb0Pz8JKIUo9l/gpSYrUghx1jdVwirENAoVXJCuLO/zBDZ5 +ytE416QakZ6QlqJVs7dwzLAt5PPjfsvFx/mMjoiFVGwq6slgCRrL188TyFYe+y6DEKx CBuanOyA2LssON24zvIxmudbjmeT1WkaL2R8kk6x4oqFTtOrgb9cBCGxjngMk+E7VDoK 5T4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=p8Jvf/lKOlrdJnYYTQwvQ4jk7EM8WIiBma3ZPM/hMGk=; b=O1cogWSR9yqt54l95jhzQ+DEMWaK02/jfUmTVvwpmVg41g5wpZcf4jtaNsiKz1vnQg XU+6lJ+cx7g2kwaew5JJAU3NNr71WdfF50g6/wSIvqVTGNYDGr2XzpABi+UOHhfTg4t9 NFajWQJfQGfRdvmHDTi9IfA+529R5T9x7Wd1qoB0CA4crcFGY76+KpIveXkJW7jgLC8n +S47nYy280tfx4qkk6kbBIWMzIX2dxSMGGOtnM/4yCL2/6TkuEm4eZ+iqS33MljdsElj yZId1Ud006KHIJkbRV0V4zX+uSjks+AtRT7ZIPvl6vmcnxDcEBhyz+cSBQuVXOMzSkos 0q0g== X-Gm-Message-State: AOAM532tCBaIdBCYlhffVRikJ6VS1xr5ky2xY1f0UBX/t3Zk3PhBDwvu I1CDTsC96XFsL9/bU4Le3+WTVVYVfF8Q3A== X-Google-Smtp-Source: ABdhPJy/aCywYF608fGkohGpuZMC9vr95CzznZWI8Z4lUldHesSUFezqahUtu1zL8vZICBCOUVzJtA== X-Received: by 2002:a1c:7308:: with SMTP id d8mr22160490wmb.55.1600558473042; Sat, 19 Sep 2020 16:34:33 -0700 (PDT) Received: from localhost.localdomain ([94.250.162.52]) by smtp.gmail.com with ESMTPSA id 91sm13945129wrq.9.2020.09.19.16.34.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 16:34:32 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Sep 2020 01:34:16 +0200 Message-Id: <20200919233416.12941-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avcodec/cfhd: check that lowpass_height is >= 3 when used in vertical filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also return early when encountering fatal error. Signed-off-by: Paul B Mahol --- libavcodec/cfhd.c | 50 ++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) 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;