From patchwork Fri Sep 25 22:26:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 22591 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 137E2448B73 for ; Sat, 26 Sep 2020 01:27:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 000D868AC4C; Sat, 26 Sep 2020 01:27:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe01-2.mx.upcmail.net (vie01a-dmta-pe01-2.mx.upcmail.net [62.179.121.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37A9A68ABC3 for ; Sat, 26 Sep 2020 01:27:40 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1kLwBo-0005DW-0K for ffmpeg-devel@ffmpeg.org; Sat, 26 Sep 2020 00:27:40 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id LwAqkHEX8Ir7GLwAqkWXzM; Sat, 26 Sep 2020 00:26:40 +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=QN4WuTDL 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=-ZpY-vuE6ZU6Tlr_55cA:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=UDnyf2zBuKT2w-IlGP_r:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 26 Sep 2020 00:26:38 +0200 Message-Id: <20200925222638.23675-6-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925222638.23675-1-michael@niedermayer.cc> References: <20200925222638.23675-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfI8DAkpcrW5BokssboQ6USz8VUuoL/8grMYsDLOncveA/ty+vRcRcnC4cpTHh49hRERtoiLXppC0fkmBDkvl7CSTEtj3DQnz+yoAa3AB9rqHCVEZROM3 nCWfnJAPVF+jQc2VmKSorvcVq8wevwQ4pTpJeYQ7ijxADdUwaQNXrE9I Subject: [FFmpeg-devel] [PATCH 6/6] avcodec/decode: Consider discarded samples in max_samples 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 (several minutes -> 3 sec) Fixes: 25246/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ALS_fuzzer-5943400661254144 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/decode.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 3ef1ece25b..257abc7de4 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -318,7 +318,7 @@ static int64_t guess_correct_pts(AVCodecContext *ctx, * returning any output, so this function needs to be called in a loop until it * returns EAGAIN. **/ -static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame) +static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) { AVCodecInternal *avci = avctx->internal; DecodeSimpleContext *ds = &avci->ds; @@ -411,12 +411,14 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame) !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) { avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples); got_frame = 0; + *discarded_samples += frame->nb_samples; } if (avci->skip_samples > 0 && got_frame && !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) { if(frame->nb_samples <= avci->skip_samples){ got_frame = 0; + *discarded_samples += frame->nb_samples; avci->skip_samples -= frame->nb_samples; av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n", avci->skip_samples); @@ -444,6 +446,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n", avci->skip_samples, frame->nb_samples); + *discarded_samples += avci->skip_samples; frame->nb_samples -= avci->skip_samples; avci->skip_samples = 0; } @@ -452,6 +455,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (discard_padding > 0 && discard_padding <= frame->nb_samples && got_frame && !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) { if (discard_padding == frame->nb_samples) { + *discarded_samples += frame->nb_samples; got_frame = 0; } else { if(avctx->pkt_timebase.num && avctx->sample_rate) { @@ -544,9 +548,12 @@ FF_ENABLE_DEPRECATION_WARNINGS static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame) { int ret; + int64_t discarded_samples = 0; while (!frame->buf[0]) { - ret = decode_simple_internal(avctx, frame); + if (discarded_samples > avctx->max_samples) + return AVERROR(EAGAIN); + ret = decode_simple_internal(avctx, frame, &discarded_samples); if (ret < 0) return ret; }