From patchwork Sun Mar 26 22:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 40848 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp885867pzh; Sun, 26 Mar 2023 15:26:55 -0700 (PDT) X-Google-Smtp-Source: AKy350bYx5ShMSetfmQs0K/L/8cIzY7JexXzrs3jiVR1aU1tXdPInx4dTHvoTmw/MmMzZji0mLMb X-Received: by 2002:aa7:d14e:0:b0:500:58cb:3b05 with SMTP id r14-20020aa7d14e000000b0050058cb3b05mr9711554edo.27.1679869615731; Sun, 26 Mar 2023 15:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679869615; cv=none; d=google.com; s=arc-20160816; b=ua6ssihbkRgSJtb/2q0oidhKXjdQCbLJpKvYThE+OZoXjpCgGwWm/Ohstw3jjcuaUI MzELG58V9RTVhwtXS5bOOzCSu0yXfSGPsB6tfyoUJNo0tNJ0DVRTCEV6vqxeXJRB3Me2 GXWYxQsHTnavsbBUoh8qVqWsloz1gbqIuom0VhY0Hnx3bzv+CAt3VJT5nY1hiRam9EWn 6hrog+kUut/zfll9ArlcQiide9jHpJpl6eKM+6I/ac4ce9su3EBW28+IeM3pP0Mc3tNJ FMs7EZjcXV8PUOWKsJonTLQxJUB4gygOdOy04ccfgN/CO2F4ttilxeEi+FavI0Vw9A7l XuPA== 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; bh=OG1yxWKzbHpGpu9ACkaUOW5WYlTDxnRC1EIiov5VHns=; b=x41VrwACpve9e7kTa+fzvT6g8MSWASRwr+TmpktS63GgzzxvhO78RHWRvNeIEOPdNf dApIrU/XMZELW9K7+qSHU+3ixFeVykHk52aGRvgfllFqxknn5l/XeFFDBlbXbZyCMeb1 C0hnrCPRRGZhLEWhz+Ru4f42VpzSGHawXs7LKtYLullPcsuAuVXk9mgQGq3n0Lzk/zEP b8/QYMq1Pe0u4UYkszI+i7fu0xS/6nvMOTGAup3Uf413hU+3fXLoufe9jmpw/JcvRY3I T4XC+Azvg1kCTAH1hjj49ZjIiJzFuAALSIAOneei6m2+KIVGMWWLj5qFzkpanvRLo67h dCRw== 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 m6-20020a50ef06000000b004acdca4e902si25647037eds.127.2023.03.26.15.26.55; Sun, 26 Mar 2023 15:26:55 -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 5B7A268C477; Mon, 27 Mar 2023 01:26:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E9D3068C618 for ; Mon, 27 Mar 2023 01:26:44 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id D1253240002 for ; Sun, 26 Mar 2023 22:26:43 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 27 Mar 2023 00:26:40 +0200 Message-Id: <20230326222642.2489-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230326222642.2489-1-michael@niedermayer.cc> References: <20230326222642.2489-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/vc1dec: Use av_fast_realloc() for slices 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: gQmCviVg4dMR Fixes: Timeout Fixes: 57281/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VC1IMAGE_fuzzer-4594141064724480 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/vc1dec.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 5cb4c544c9a..18fb616fff5 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -836,6 +836,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, const uint8_t *rawbuf; int raw_size; } *slices = NULL, *tmp; + unsigned slices_allocated = 0; v->second_field = 0; @@ -859,6 +860,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, //for advanced profile we may need to parse and unescape data if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { int buf_size2 = 0; + size_t next_allocated = 0; buf2 = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!buf2) return AVERROR(ENOMEM); @@ -882,7 +884,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, int buf_size3; if (avctx->hwaccel) buf_start_second_field = start; - tmp = av_realloc_array(slices, sizeof(*slices), n_slices+1); + av_size_mult(sizeof(*slices), n_slices+1, &next_allocated); + tmp = next_allocated ? av_fast_realloc(slices, &slices_allocated, next_allocated) : NULL; if (!tmp) { ret = AVERROR(ENOMEM); goto err; @@ -911,7 +914,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, break; case VC1_CODE_SLICE: { int buf_size3; - tmp = av_realloc_array(slices, sizeof(*slices), n_slices+1); + av_size_mult(sizeof(*slices), n_slices+1, &next_allocated); + tmp = next_allocated ? av_fast_realloc(slices, &slices_allocated, next_allocated) : NULL; if (!tmp) { ret = AVERROR(ENOMEM); goto err; @@ -946,7 +950,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, } else { // found field marker, unescape second field if (avctx->hwaccel) buf_start_second_field = divider; - tmp = av_realloc_array(slices, sizeof(*slices), n_slices+1); + av_size_mult(sizeof(*slices), n_slices+1, &next_allocated); + tmp = next_allocated ? av_fast_realloc(slices, &slices_allocated, next_allocated) : NULL; if (!tmp) { ret = AVERROR(ENOMEM); goto err;