From patchwork Sun Aug 15 19:25:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 29546 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1431699iov; Sun, 15 Aug 2021 12:27:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMyVvSu4+oirwe4KxTyNIczBd8aOUZ0wi34CRMh3zmZ64SxicVjg2jrS3qyA3G5nHRmmlH X-Received: by 2002:a05:6402:31bc:: with SMTP id dj28mr15690000edb.143.1629055627536; Sun, 15 Aug 2021 12:27:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629055627; cv=none; d=google.com; s=arc-20160816; b=OsBQPJeJNxTYVTtkLb2YWBj75biYuszJwGOwWcu6sOOApJo0iEVanZdF2dlDPTPigy F93eAuIcVO6Q0B4F8FtgF9eNc9865BKIbi4zQdW1q/uLXIG90ztnxUv8/j+x7ye2sWbh 2xusszehNasm8N0mCZtrEGo7/LyGJeKFsI3y/RkZXD/UW6XIhy5KaIpuxCGlJDObuExb J956+qwwqSEGuc3sB76Ee7d+N0MtfoPpwKEYfLZg5ebm+76cbrIMMji5WMELTxqnPOVE oLj3FzjKzA0s7pTgqRaBEgxH2DUpIW3kB3unHygeZeYCUgtgTdFFNLab0BulUSx7gZd9 d5tQ== 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:message-id:date:to:from:delivered-to; bh=ouoB9tOfxPA0odZYY7meM/CeapaugBHzbVhywDJBWRM=; b=TJl+aQeXrcxfEoYzw5kKF0Cuw5OG2tAduOfh/v8qGKsx6hg/p5UtpzhW/jqfAVoaBZ SnQV0NScoNRHcAQtJlz+fYqwimcsRORTrKrx3FFFSPyciRdcfh/taDVNOXu+lK2pzpDl TLo1o0OglbLdl4kZcV270pd7DAWnTRlBSeeX1WK1fj1pLRl1q8TBzycQwEfOyYfCPELE +Xir1aEKT1d2spjAaXZ13UuYGI+f3ZpQXq2MgTRMGSSEJHOAy0VhlSWW/oskJhRNXk48 ZGxXcztbYw3oXECJNKitLwDT4DttpmtVxhCu3t95IKkCtM6mN8BmQAose2swPnfCMqvS PdTQ== 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 g24si8707347edj.498.2021.08.15.12.27.06; Sun, 15 Aug 2021 12:27:07 -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 ED54668A214; Sun, 15 Aug 2021 22:27:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe03-2.mx.upcmail.net (vie01a-dmta-pe03-2.mx.upcmail.net [62.179.121.161]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C594F689248 for ; Sun, 15 Aug 2021 22:26:55 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1mFLmZ-00GjDP-0m for ffmpeg-devel@ffmpeg.org; Sun, 15 Aug 2021 21:26:55 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id FLlbmKdx4ljeHFLlbmrw1n; Sun, 15 Aug 2021 21:25:55 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=BoHjPrf5 c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=vLR8AIf4O5iOLkxsdYQA:9 a=1fhp2MxaeJtTNGEnv6mo:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 15 Aug 2021 21:25:54 +0200 Message-Id: <20210815192554.14648-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfBcFWJGm3vsN4T2sHDxPUXJdSYxy/QYVnoqCBETC5Sv9FWisE+qVNWiDy4yLcVkinwXV+MLcfRhhgJ7eicP3AIMb7/UbCoFt90hdVAD52rYuVku4Gseb BlW84WzSIpLXuM0mDlW8M6wre9nf0tiaZKC2lBavvS56MAN4aISP8oEx Subject: [FFmpeg-devel] [PATCH] avcodec/snowdec: Maintain avmv buffer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: DwfPo1C9da09 This avoids reallocating per frame Fixes: Assertion failure Fixes: 36359/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SNOW_fuzzer-6733238591684608 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/snow.h | 1 + libavcodec/snowdec.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libavcodec/snow.h b/libavcodec/snow.h index c0d2599859..8795491cf3 100644 --- a/libavcodec/snow.h +++ b/libavcodec/snow.h @@ -186,6 +186,7 @@ typedef struct SnowContext{ uint8_t *emu_edge_buffer; AVMotionVector *avmv; + unsigned avmv_size; int avmv_index; uint64_t encoding_error[AV_NUM_DATA_POINTERS]; diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c index 1355ae6ed1..cd2265aba1 100644 --- a/libavcodec/snowdec.c +++ b/libavcodec/snowdec.c @@ -492,9 +492,17 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, s->spatial_decomposition_count ); - av_assert0(!s->avmv); if (s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) { - s->avmv = av_malloc_array(s->b_width * s->b_height, sizeof(AVMotionVector) << (s->block_max_depth*2)); + size_t size; + res = av_size_mult(s->b_width * s->b_height, sizeof(AVMotionVector) << (s->block_max_depth*2), &size); + if (res) + return res; + av_fast_malloc(&s->avmv, &s->avmv_size, size); + if (!s->avmv) + return AVERROR(ENOMEM); + } else { + s->avmv_size = 0; + av_freep(&s->avmv); } s->avmv_index = 0; @@ -623,8 +631,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, memcpy(sd->data, s->avmv, s->avmv_index * sizeof(AVMotionVector)); } - av_freep(&s->avmv); - if (res < 0) return res; @@ -644,6 +650,9 @@ static av_cold int decode_end(AVCodecContext *avctx) ff_snow_common_end(s); + s->avmv_size = 0; + av_freep(&s->avmv); + return 0; }