From patchwork Tue Aug 1 23:28:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 4580 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp530528vsu; Tue, 1 Aug 2017 16:28:45 -0700 (PDT) X-Received: by 10.223.156.25 with SMTP id f25mr5457871wrc.154.1501630125337; Tue, 01 Aug 2017 16:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501630125; cv=none; d=google.com; s=arc-20160816; b=F+dzgPYlDjhGoVCwPH2hnFvjqqaGI83hvSkz3CqkKPsSzzISBrbWRAXyqUtqXnsmQ8 5LKuWfwWOubLw1yc7TZ1fpTFrBF6u2Z16YuWJCGJRxB4+0U5eSRyTUvhBNp9pJd7CyxY vARq31P9lFDBL0n+T4TLWvIorQIbO+ExWyoH1bnaswcDdp8lQ0W89/j655dGyNpMXYdH qBmP7bYmnYpDWe/FFpn1G1/HAd4Qe51R2/rGVg7ogim6KDc4HCWOT+Wf4l2Zb1YzhRsJ iHHx8pDiNqLbO1jdoQn5B0y6/6EWrppIsBQVXglrVdRhCR+qiBpUDxPVfsGTBTyZiSaQ uZSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=zpuypIIAiYLUDBUBMVM1DhvcB20niEQzM2xxwzJje3I=; b=L0U7Z/P30qZwtUyjw9MVWOe4+I+H1uihnFSj756Vizex2qbTeijIogr+8nLTJCDFq2 icdNBtMGuT1Pm2KIP62a2EPHVZPO6XEiqsSEwzoJ3IpVeDywqz93TvHoIfzcwII5DS6q frCV7T9Xn1HmDTf/Nuc9idtuqAhqXyThsLYJqCibIpgByh/ZxRmCyyNhX/jugWsN/gPf PXX5SiNseBg4Y3KfSCFTSka7BUi776mkQiqCMG2yJ0kIPr7EK9k0IijNLrUQgU1AppPe rL3+WGUt4LQra2XfdULAW26DQouRxsqu0CcgQvhyIUeu0b5+96/H2XaKfuJh+4bqvkrI wUYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p78si24046698wrb.406.2017.08.01.16.28.44; Tue, 01 Aug 2017 16:28:45 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F8EF68A3B2; Wed, 2 Aug 2017 02:28:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-1.mx.upcmail.net (vie01a-qmta-pe02-1.mx.upcmail.net [62.179.121.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7965268A1BE for ; Wed, 2 Aug 2017 02:28:25 +0300 (EEST) Received: from [172.31.218.32] (helo=vie01a-dmta-pe01-2.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dcgaS-00028t-By for ffmpeg-devel@ffmpeg.org; Wed, 02 Aug 2017 01:28:28 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dcgaN-0006EK-1o for ffmpeg-devel@ffmpeg.org; Wed, 02 Aug 2017 01:28:23 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id rzUL1v01E0S5wYM01zUMv7; Wed, 02 Aug 2017 01:28:22 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 2 Aug 2017 01:28:18 +0200 Message-Id: <20170801232818.7985-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170801232818.7985-1-michael@niedermayer.cc> References: <20170801232818.7985-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/hevc_cabac: Check for ff_init_cabac_decoder() failure in cabac_reinit() 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: runtime error: left shift of negative value -967831544 Fixes: 2815/clusterfuzz-testcase-minimized-6062914471460864 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/hevc_cabac.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c index 4c14e77bcd..853fd3f722 100644 --- a/libavcodec/hevc_cabac.c +++ b/libavcodec/hevc_cabac.c @@ -462,9 +462,9 @@ static void load_states(HEVCContext *s) memcpy(s->HEVClc->cabac_state, s->cabac_state, HEVC_CONTEXTS); } -static void cabac_reinit(HEVCLocalContext *lc) +static int cabac_reinit(HEVCLocalContext *lc) { - skip_bytes(&lc->cc, 0); + return skip_bytes(&lc->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0; } static int cabac_init_decoder(HEVCContext *s) @@ -524,25 +524,27 @@ int ff_hevc_cabac_init(HEVCContext *s, int ctb_addr_ts) } else { if (s->ps.pps->tiles_enabled_flag && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) { + int ret; if (s->threads_number == 1) - cabac_reinit(s->HEVClc); + ret = cabac_reinit(s->HEVClc); else { - int ret = cabac_init_decoder(s); - if (ret < 0) - return ret; + ret = cabac_init_decoder(s); } + if (ret < 0) + return ret; cabac_init_state(s); } if (s->ps.pps->entropy_coding_sync_enabled_flag) { if (ctb_addr_ts % s->ps.sps->ctb_width == 0) { + int ret; get_cabac_terminate(&s->HEVClc->cc); if (s->threads_number == 1) - cabac_reinit(s->HEVClc); + ret = cabac_reinit(s->HEVClc); else { - int ret = cabac_init_decoder(s); - if (ret < 0) - return ret; + ret = cabac_init_decoder(s); } + if (ret < 0) + return ret; if (s->ps.sps->ctb_width == 1) cabac_init_state(s);