From patchwork Wed Jan 9 00:01:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 11682 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 DEAB644D85F for ; Wed, 9 Jan 2019 02:02:44 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9AB0868A67A; Wed, 9 Jan 2019 02:02:41 +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 E34CB68A45B for ; Wed, 9 Jan 2019 02:02:33 +0200 (EET) Received: from [172.31.218.49] (helo=vie01a-dmta-pe07-1.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1gh1KX-0000uh-1n 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-pe07.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1gh1KR-0007rl-0b for ffmpeg-devel@ffmpeg.org; Wed, 09 Jan 2019 01:02:39 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id h1JTgwCCR2WSsh1JTgufZm; Wed, 09 Jan 2019 01:01:39 +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=BvCCfgCYPxFZSy7TPpsA:9 a=pHzHmUro8NiASowvMSCR:22 a=n87TN5wuljxrRezIQYnT:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 9 Jan 2019 01:01:21 +0100 Message-Id: <20190109000122.17610-2-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: MS4wfIVo8twn9Fi69Ct6GfinyDvnagbsKjreqO16Tia4Anh7UBPs5DMvb7/lk2qPr+5INms6EC+INhj8Jtrq9LLGXNJkAHWfH8NwbHbkDPCE8FbQWRlKiBVA avgP2MYUHZaMd3xqDMaHms/o1hJcK++j5MUPGDdUOstTd6L3QLnYUzNZ Subject: [FFmpeg-devel] [PATCH 2/3] oavcodec/diracdec: Propagate errors from dirac_get_arith_uint() 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" Testcase: 11663/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016 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 | 2 ++ libavcodec/diracdec.c | 2 ++ 3 files changed, 5 insertions(+) diff --git a/libavcodec/dirac_arith.c b/libavcodec/dirac_arith.c index 7eb9bd60b2..1e6b964772 100644 --- a/libavcodec/dirac_arith.c +++ b/libavcodec/dirac_arith.c @@ -115,6 +115,7 @@ void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length) c->counter = -16; c->range = 0xffff; + c->error = 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 24a7ca390e..efe30b79de 100644 --- a/libavcodec/dirac_arith.h +++ b/libavcodec/dirac_arith.h @@ -81,6 +81,7 @@ typedef struct { const uint8_t *bytestream_end; uint16_t contexts[DIRAC_CTX_COUNT]; + int error; } DiracArith; extern const uint8_t ff_dirac_next_ctx[DIRAC_CTX_COUNT]; @@ -173,6 +174,7 @@ static inline int dirac_get_arith_uint(DiracArith *c, int follow_ctx, int data_c while (!dirac_get_arith_bit(c, follow_ctx)) { if (ret >= 0x40000000) { av_log(NULL, AV_LOG_ERROR, "dirac_get_arith_uint overflow\n"); + c->error = AVERROR_INVALIDDATA; return -1; } ret <<= 1; diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c index fd23139062..db010b49cf 100644 --- a/libavcodec/diracdec.c +++ b/libavcodec/diracdec.c @@ -537,6 +537,8 @@ static inline int codeblock(DiracContext *s, SubBand *b, buf = b->ibuf + top * b->stride; if (is_arith) { for (y = top; y < bottom; y++) { + if (c->error) + return c->error; for (x = left; x < right; x++) { if (b->pshift) { coeff_unpack_arith_10(c, qfactor, qoffset, b, (int32_t*)(buf)+x, x, y);