From patchwork Wed Aug 14 07:00:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 14499 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 2DA54449AE8 for ; Wed, 14 Aug 2019 10:07:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F31C768A9BB; Wed, 14 Aug 2019 10:07:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe07-1.mx.upcmail.net (vie01a-dmta-pe07-1.mx.upcmail.net [84.116.36.17]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9031F68A5EE for ; Wed, 14 Aug 2019 10:07:37 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe07.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1hxnID-0006qI-Ac for ffmpeg-devel@ffmpeg.org; Wed, 14 Aug 2019 09:01:57 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id xnHEht7tDwlysxnHFhRzUz; Wed, 14 Aug 2019 09:00:57 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.41.20 X-CNFS-Analysis: v=2.3 cv=E5OzWpVl c=1 sm=1 tr=0 a=I1eytVlZLDX1BM2VTtTtSw==:117 a=I1eytVlZLDX1BM2VTtTtSw==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=wa1tvrJdIoOtRAzI8t0A:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=UDnyf2zBuKT2w-IlGP_r:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 14 Aug 2019 09:00:08 +0200 Message-Id: <20190814070008.8677-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20190814070008.8677-1-michael@niedermayer.cc> References: <20190814070008.8677-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfNjveNGZTHQjqCs7y3992IT2QM2MQYbZynPyK+pgf6V7VkjEPMUcf5inyPb6RJpxoxBnKm9jciVPEP+7kdYOAMZYVCt18LJv2bLrXzCbu1FyQvoxrIs9 ZZreUYB06KCBZqUZ6L4lIQOoGZM+kV27ulO/djRoOgmsqvB7vSCVTZhA Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/ivi: Allocate bufs later 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes: Timeout (24sec->2sec) Fixes: 15951/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_INDEO5_fuzzer-5095433266790400 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/ivi.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/libavcodec/ivi.c b/libavcodec/ivi.c index 73fcf51b7b..18192cbf23 100644 --- a/libavcodec/ivi.c +++ b/libavcodec/ivi.c @@ -354,23 +354,11 @@ av_cold int ff_ivi_init_planes(AVCodecContext *avctx, IVIPlaneDesc *planes, cons band->height = b_height; band->pitch = width_aligned; band->aheight = height_aligned; - band->bufs[0] = av_mallocz(buf_size); - band->bufs[1] = av_mallocz(buf_size); + av_assert0(!band->bufs[0] && !band->bufs[1] && + !band->bufs[2] && !band->bufs[3]); band->bufsize = buf_size/2; - if (!band->bufs[0] || !band->bufs[1]) - return AVERROR(ENOMEM); + av_assert0(buf_size % 2 == 0); - /* allocate the 3rd band buffer for scalability mode */ - if (cfg->luma_bands > 1) { - band->bufs[2] = av_mallocz(buf_size); - if (!band->bufs[2]) - return AVERROR(ENOMEM); - } - if (is_indeo4) { - band->bufs[3] = av_mallocz(buf_size); - if (!band->bufs[3]) - return AVERROR(ENOMEM); - } /* reset custom vlc */ planes[p].bands[0].blk_vlc.cust_desc.num_rows = 0; } @@ -945,6 +933,15 @@ static void ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, ptrdiff_t dst_pi } } +static void *prepare_buf(IVI45DecContext *ctx, IVIBandDesc *band, int i) +{ + if (ctx->pic_conf.luma_bands <= 1 && i == 2) + return NULL; + if (!band->bufs[i]) + band->bufs[i] = av_mallocz(2 * band->bufsize); + return band->bufs[i]; +} + /** * Decode an Indeo 4 or 5 band. * @@ -959,18 +956,22 @@ static int decode_band(IVI45DecContext *ctx, int result, i, t, idx1, idx2, pos; IVITile *tile; - band->buf = band->bufs[ctx->dst_buf]; + band->buf = prepare_buf(ctx, band, ctx->dst_buf); if (!band->buf) { av_log(avctx, AV_LOG_ERROR, "Band buffer points to no data!\n"); return AVERROR_INVALIDDATA; } if (ctx->is_indeo4 && ctx->frame_type == IVI4_FRAMETYPE_BIDIR) { - band->ref_buf = band->bufs[ctx->b_ref_buf]; - band->b_ref_buf = band->bufs[ctx->ref_buf]; + band->ref_buf = prepare_buf(ctx, band, ctx->b_ref_buf); + band->b_ref_buf = prepare_buf(ctx, band, ctx->ref_buf); + if (!band->b_ref_buf) + return AVERROR(ENOMEM); } else { - band->ref_buf = band->bufs[ctx->ref_buf]; + band->ref_buf = prepare_buf(ctx, band, ctx->ref_buf); band->b_ref_buf = 0; } + if (!band->ref_buf) + return AVERROR(ENOMEM); band->data_ptr = ctx->frame_data + (get_bits_count(&ctx->gb) >> 3); result = ctx->decode_band_hdr(ctx, band, avctx);