From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7855445C29 for ; Sun, 26 Mar 2023 22:26:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 28F9268C627; Mon, 27 Mar 2023 01:26:51 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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; -- 2.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".