From patchwork Thu Jan 17 00:42:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 11774 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 95B0044DBE9 for ; Thu, 17 Jan 2019 02:43:57 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B529968AA1E; Thu, 17 Jan 2019 02:43:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe07-2.mx.upcmail.net (vie01a-dmta-pe07-2.mx.upcmail.net [84.116.36.18]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C324068AA1E for ; Thu, 17 Jan 2019 02:43:38 +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 1gjvmj-0005l3-0L for ffmpeg-devel@ffmpeg.org; Thu, 17 Jan 2019 01:43:53 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id jvlkgwHhW2WSsjvlkggpr8; Thu, 17 Jan 2019 01:42:52 +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: Thu, 17 Jan 2019 01:42:48 +0100 Message-Id: <20190117004248.14128-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CMAE-Envelope: MS4wfJhFhoSGupDa3l6fNBDhQyQZm9Qp2ps+r6OOBb1r8qX0iMIrgV4x53jO1Q6B8KUoLBNpPZNnUFsFFdCI00hXHwPmmDRYRbx46dijK/phzG6SWaEi27qI yjoUr97voAdiIbZ3GXTyrmkno+qDR5yQ9aqKo0hUS0KI3vMlgNDBMv81 Subject: [FFmpeg-devel] [PATCH] 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..fa066afd7f 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 more than 5% 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/20) + *got_frame = 1; ret = avpkt->size; end: