From patchwork Sun Aug 26 23:50:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 10149 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp5836648jap; Sun, 26 Aug 2018 16:51:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYKeBOWa1QjecwnMAecVRQJIsc18+cDVQ6ANUCHgZa/tr8URxgm9qAYIYNoC3rgmdCfgdId X-Received: by 2002:a1c:9c56:: with SMTP id f83-v6mr3917762wme.135.1535327486255; Sun, 26 Aug 2018 16:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535327486; cv=none; d=google.com; s=arc-20160816; b=dsS9CVGHo9l7K07brlTxM7syhgKyhMQHJffvZBnEUS4U0U88lXJ6jcZqRw5/B/jjg0 En2yMFiDTe4amtRu/r++5seJlp3ZHMocilYsKkZGSq+kzUpyR0iN3VKvag876FppF/jh 3o+yuFVY8cPr0yQR9/cnKYYmYtpE1LlzprZ7+mbWDs8jN7qmPPPKScCQzDjNnn0ZR5lW JjlANQrdW+PY+MwhUi/qGVFpMAhOEhBcP0TJoPG2NWJFAyExMoKptaeWRSLhtPK+ZpGp ugt4S+DK2rrqG/3mz4tg/BPgg8WMGTqJ+2cOLQR9S8qwPPwiA79UO6OtGWZaGR+h9zjK 3jeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=363/QPFgQzFhATw1TKwOACAKtr039UJWhvPwQnuTuUs=; b=EToHy0DaUO/GzF/jO3rMPEeB37S1LgST4msOQffnjgdCh2/+s8cDoMtcZpNlzHakj3 SsQLRPpJBvPtAJt+I92aFO6dZbccxU53aEaWuih7VqAFeLcKVuGVpQYUONY5AVZIdawh 8q2ZUP9TFSsXBUA+b9RV12TcrcsSZwhcoVCzDp7yFjW0vIuTJ4/AJi4HAARudHPID34J gfHNFuDY+j872MHkUjbz7i2VZ4VPBrYQB4aXJ+nW7xrNjpeSCM0+Kpcy2SqoQMOut8Y1 LdO/n9JuCG5tfrghA3Uw4/NYWqqroJjGobb7ULQo0xrKzmilHo7y5+w/x02wLic9Ygf0 vy+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c4-v6si8833273wrw.86.2018.08.26.16.51.25; Sun, 26 Aug 2018 16:51:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1B02B689B6F; Mon, 27 Aug 2018 02:51:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-1.mx.upcmail.net (vie01a-dmta-pe06-1.mx.upcmail.net [84.116.36.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BF312689B19 for ; Mon, 27 Aug 2018 02:51:00 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fu4oB-0004OF-O3 for ffmpeg-devel@ffmpeg.org; Mon, 27 Aug 2018 01:51:03 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id Tzqu1y00K0S5wYM01zqvMW; Mon, 27 Aug 2018 01:50:55 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 27 Aug 2018 01:50:37 +0200 Message-Id: <20180826235037.24153-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180826235037.24153-1-michael@niedermayer.cc> References: <20180826235037.24153-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 3/3] iavcodec/zmbv: Avoid reallocating cur/prev buffers if they are large enough 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" Fixes: Timeout Fixes: 9721/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ZMBV_fuzzer-5650321660444672 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/zmbv.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c index 251a72cf31..b01ce1bcf6 100644 --- a/libavcodec/zmbv.c +++ b/libavcodec/zmbv.c @@ -57,6 +57,7 @@ typedef struct ZmbvContext { AVCodecContext *avctx; int bpp; + int alloc_bpp; unsigned int decomp_size; uint8_t* decomp_buf; uint8_t pal[768]; @@ -494,12 +495,17 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac return AVERROR_UNKNOWN; } - c->cur = av_realloc_f(c->cur, avctx->width * avctx->height, (c->bpp / 8)); - c->prev = av_realloc_f(c->prev, avctx->width * avctx->height, (c->bpp / 8)); + if (c->alloc_bpp < c->bpp) { + c->cur = av_realloc_f(c->cur, avctx->width * avctx->height, (c->bpp / 8)); + c->prev = av_realloc_f(c->prev, avctx->width * avctx->height, (c->bpp / 8)); + c->alloc_bpp = c->bpp; + } c->bx = (c->width + c->bw - 1) / c->bw; c->by = (c->height+ c->bh - 1) / c->bh; - if (!c->cur || !c->prev) + if (!c->cur || !c->prev) { + c->alloc_bpp = 0; return AVERROR(ENOMEM); + } memset(c->cur, 0, avctx->width * avctx->height * (c->bpp / 8)); memset(c->prev, 0, avctx->width * avctx->height * (c->bpp / 8)); c->decode_intra= decode_intra;