From patchwork Sat Nov 9 22:39:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 16182 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 CB123448C0D for ; Sun, 10 Nov 2019 00:41:43 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B4F8168B008; Sun, 10 Nov 2019 00:41:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-2.mx.upcmail.net (vie01a-dmta-pe05-2.mx.upcmail.net [84.116.36.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B551D68AE9A for ; Sun, 10 Nov 2019 00:41:32 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1iTZQC-00064p-0H for ffmpeg-devel@ffmpeg.org; Sat, 09 Nov 2019 23:41:32 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id TZPEiM4P7wlysTZPEiRHm0; Sat, 09 Nov 2019 23:40:32 +0100 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=E5OzWpVl c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=eRKT-vuvfG1WOuzCGkUA:9 a=MKaXUKzrofujhr_J:21 a=c_75NaBlLmO7LRUv:21 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=UDnyf2zBuKT2w-IlGP_r:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 9 Nov 2019 23:39:07 +0100 Message-Id: <20191109223907.11014-7-michael@niedermayer.cc> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191109223907.11014-1-michael@niedermayer.cc> References: <20191109223907.11014-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfOBBxCyR409IcKOrxCxMylwvXSY2BHpQLv+B4GV0qiQUds2vKOKI3MyZNwPYbsyfXQu/LU3hite8To6XB/KMMhipApDJAPXmGMLeAFm5YVjDzLychont /ns/7YVhcKmZFtuIheoY85em1CFHc579IWpARwNga7Ajyd9YkF3XmrC5 Subject: [FFmpeg-devel] [PATCH 7/7] avcodec/alsdec: Discard frames for which no channel could be decoded 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 (80sec -> 33sec) Fixes: 18668/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ALS_fuzzer-5710836719157248 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/alsdec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index babe30bdc7..62c6036037 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -236,6 +236,7 @@ typedef struct ALSDecContext { int **raw_mantissa; ///< decoded mantissa bits of the difference signal unsigned char *larray; ///< buffer to store the output of masked lz decompression int *nbits; ///< contains the number of bits to read for masked lz decompression for all samples + int highest_decoded_channel; } ALSDecContext; @@ -1678,6 +1679,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) memmove(ctx->raw_samples[c] - sconf->max_order, ctx->raw_samples[c] - sconf->max_order + sconf->frame_length, sizeof(*ctx->raw_samples[c]) * sconf->max_order); + ctx->highest_decoded_channel = c; } } else { // multi-channel coding ALSBlockData bd = { 0 }; @@ -1746,6 +1748,8 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) if ((ret = decode_block(ctx, &bd)) < 0) return ret; + + ctx->highest_decoded_channel = FFMAX(ctx->highest_decoded_channel, c); } memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels)); @@ -1802,11 +1806,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, else ctx->cur_frame_length = sconf->frame_length; + ctx->highest_decoded_channel = 0; // decode the frame data if ((invalid_frame = read_frame_data(ctx, ra_frame)) < 0) av_log(ctx->avctx, AV_LOG_WARNING, "Reading frame data failed. Skipping RA unit.\n"); + if (ctx->highest_decoded_channel == 0) + return AVERROR_INVALIDDATA; + ctx->frame_id++; /* get output buffer */