From patchwork Fri Jan 18 23:00:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 11796 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 2A8A444D991 for ; Sat, 19 Jan 2019 01:06:34 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4866668ACC4; Sat, 19 Jan 2019 01:06:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe07-1.mx.upcmail.net (vie01a-dmta-pe07-1.mx.upcmail.net [84.116.36.17]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C470968ACBF for ; Sat, 19 Jan 2019 01:06:16 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe07.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1gkdDc-0000db-6e for ffmpeg-devel@ffmpeg.org; Sat, 19 Jan 2019 00:06:32 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id kd8Bgzeq52WSskd8Bg3kcl; Sat, 19 Jan 2019 00:00:55 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.41.20 X-CNFS-Analysis: v=2.3 cv=E7kcWpVl c=1 sm=1 tr=0 a=I1eytVlZLDX1BM2VTtTtSw==:117 a=I1eytVlZLDX1BM2VTtTtSw==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=HeICI_j-1szIvdO3s5AA:9 a=pHzHmUro8NiASowvMSCR:22 a=nt3jZW36AmriUCFCBwmW:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 19 Jan 2019 00:00:49 +0100 Message-Id: <20190118230049.23122-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190118230049.23122-1-michael@niedermayer.cc> References: <20190118230049.23122-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfN+btcL8gjyPoZizYovYjtHL4y/NC6WtjU3xPfC0dVuVlkkzmoUoQqL1TBQPIZAubKOKv+GV/NXp9DwlEySsnJk+C5QR8NmV1Z/MI5dueRjlcWa5x6fo XPjLtUmhXser8CvSuIUDBJ9E265Lq4cLgAry6r8UUCe8eB96Y2fV5BXy Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/rscc: Avoid returning frames that have nearly no undamaged pixels in them 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 Fixes: 12192/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RSCC_fuzzer-6279038004363264 Before: clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RSCC_fuzzer-6279038004363264 in 15423 ms After: clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RSCC_fuzzer-6279038004363264 in 190 ms Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/rscc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/rscc.c b/libavcodec/rscc.c index 7921f149ed..3868c1cb1b 100644 --- a/libavcodec/rscc.c +++ b/libavcodec/rscc.c @@ -64,6 +64,7 @@ typedef struct RsccContext { /* zlib interaction */ uint8_t *inflated_buf; uLongf inflated_size; + int valid_pixels } RsccContext; static av_cold int rscc_init(AVCodecContext *avctx) @@ -348,7 +349,11 @@ static int rscc_decode_frame(AVCodecContext *avctx, void *data, memcpy (frame->data[1], ctx->palette, AVPALETTE_SIZE); } - *got_frame = 1; + // We only return a picture when too little is undameged, this avoids copying nearly broken frames around + if (ctx->valid_pixels < ctx->inflated_size) + ctx->valid_pixels += pixel_size; + if (ctx->valid_pixels >= ctx->inflated_size * (100 - avctx->discard_damaged_percentage) / 100) + *got_frame = 1; ret = avpkt->size; end: