From patchwork Wed Jan 9 00:01:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 11684 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 9B84A44D85F for ; Wed, 9 Jan 2019 02:02:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5220868A6B4; Wed, 9 Jan 2019 02:02:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-3.mx.upcmail.net (vie01a-qmta-pe02-3.mx.upcmail.net [62.179.121.183]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2C62068A45B for ; Wed, 9 Jan 2019 02:02:34 +0200 (EET) Received: from [172.31.218.44] (helo=vie01a-dmta-pe05-2.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1gh1KX-0000un-G6 for ffmpeg-devel@ffmpeg.org; Wed, 09 Jan 2019 01:02:45 +0100 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.88) (envelope-from ) id 1gh1KS-0003b8-2G for ffmpeg-devel@ffmpeg.org; Wed, 09 Jan 2019 01:02:40 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id h1JTgwCCy2WSsh1JTgufaA; Wed, 09 Jan 2019 01:01:40 +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=wcbd4G3nmLV0NtIlkv4A:9 a=pHzHmUro8NiASowvMSCR:22 a=nt3jZW36AmriUCFCBwmW:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 9 Jan 2019 01:01:22 +0100 Message-Id: <20190109000122.17610-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190109000122.17610-1-michael@niedermayer.cc> References: <20190109000122.17610-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfIwNgI4K3gD8DXyG5JCgyQmWPyOmT/Rjgy3l164DvSzCZlLIy7gBun3PSaWhYwCRsPZzw73+Epj1nmtfrH3R/2Q/dH7UjJx5Ndhuh8YLtvPUzlEiWXcf 2We81jluO2Dk9NxXsdnu2zzCZJHCWhaYeys3p5sLq5V9n1p4vCn/tbSs Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/dirac_arith: Treat overread as error 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: 11663/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016 Before:Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016 in 26006 ms After: Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016 in 106 ms Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/dirac_arith.c | 1 + libavcodec/dirac_arith.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/libavcodec/dirac_arith.c b/libavcodec/dirac_arith.c index 1e6b964772..36142fe198 100644 --- a/libavcodec/dirac_arith.c +++ b/libavcodec/dirac_arith.c @@ -116,6 +116,7 @@ void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length) c->counter = -16; c->range = 0xffff; c->error = 0; + c->overread= 0; for (i = 0; i < DIRAC_CTX_COUNT; i++) c->contexts[i] = 0x8000; diff --git a/libavcodec/dirac_arith.h b/libavcodec/dirac_arith.h index efe30b79de..79526a7ca3 100644 --- a/libavcodec/dirac_arith.h +++ b/libavcodec/dirac_arith.h @@ -82,6 +82,7 @@ typedef struct { uint16_t contexts[DIRAC_CTX_COUNT]; int error; + int overread; } DiracArith; extern const uint8_t ff_dirac_next_ctx[DIRAC_CTX_COUNT]; @@ -119,6 +120,9 @@ static inline void refill(DiracArith *c) new |= 0xff00; c->bytestream = c->bytestream_end; + c->overread ++; + if (c->overread > 4) + c->error = AVERROR_INVALIDDATA; } c->low += new << counter;