From patchwork Thu Jun 14 21:12:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 9414 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp2398364jad; Thu, 14 Jun 2018 14:12:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLZ5zHADHO6YHzBL5WgIaANSxQUvARFsvRB/HBiM+NM4wzRv1dffZswXyDHcvHPjmgQrmLH X-Received: by 2002:adf:a0aa:: with SMTP id m39-v6mr3574775wrm.125.1529010776529; Thu, 14 Jun 2018 14:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529010776; cv=none; d=google.com; s=arc-20160816; b=g7naQB17Zj+gJf8m7yYSOYzH5sUWjZR13Y8jrl34XONvzjgsy2HItFHBOdxB2bU1nJ IzpYk5cfjm/emSPNz8as5q1E9p4q6Gm2Z6Loik5RS8cY5TmnSaBHA8rh8PmZXTNoFeVj 7r2FecI0Mw4Aoh8nuctbrhNeaSRj66Vj4/7yC1/hDzKig7RQLirBBcYbV+Pzx77+BDs+ uEwkNDTvOY0PsXuXGEL/3wiawGNJUBPq1vEEyY3nMpZuhCsQy1TBIXHR1yUVJAgNsdHD fn2k3HOyhQ5BbvHpabeFSZdIqZ4prNisA0oUF8laQN/mlwzFrwp/4MfM6R+YnOiFQDhs wWfQ== 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:message-id:date:to:from:delivered-to :arc-authentication-results; bh=W7lSzKSrAJ/Jf23nqA/kYd4/WDdSbCJo62/RRz3DapE=; b=zp3C7ZGybJ+MkSlxJXYupJ/flNlTdcAf/UW/KP/kT/KezypOOPh5Htdofpfukdy4bz /nGr7ZmCLvIAX7s/LeiXf5gQIzHaBEmskCWZHW9J3lUOchO4U1SenpZhuL9QNZ6/R7TX rG8JpTDJBu66WsQltgDwU6MqvWK5+xL1Bcwnc4rdEvqAOCrAGZJOIz59/qitE1XC7LdG Zkkm0Qza3jIVmGY43l4SZtwk6bsr7wEm4XwTF6cd4IsamwvpSBicWN6fivrhMoIAU2ge sgrd/ybWnYbRojgD49XU8QbhjVesYa80+5/FeqLr/tr+1pXawHvYHVBE2rTjVM3h2qek WrWw== 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 p9-v6si5251369wrr.182.2018.06.14.14.12.55; Thu, 14 Jun 2018 14:12:56 -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 C9E7D68A7F9; Fri, 15 Jun 2018 00:12:03 +0300 (EEST) 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 12B2068A7A4 for ; Fri, 15 Jun 2018 00:11:57 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe07.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fTZXz-0004HF-EO for ffmpeg-devel@ffmpeg.org; Thu, 14 Jun 2018 23:12:47 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id ylCd1x00Q0S5wYM01lCeAr; Thu, 14 Jun 2018 23:12:38 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 14 Jun 2018 23:12:09 +0200 Message-Id: <20180614211209.1336-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avcodec/lagarith: Check that the range coded data stream is consistent when the probabilities indicate no data could have been coded. 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: Timeout Fixes: 8638/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LAGARITH_fuzzer-5132046098759680 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/lagarith.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavcodec/lagarith.c b/libavcodec/lagarith.c index 0f4aa89486..ba2da2eeb2 100644 --- a/libavcodec/lagarith.c +++ b/libavcodec/lagarith.c @@ -141,6 +141,7 @@ static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb) unsigned prob, cumulative_target; unsigned cumul_prob = 0; unsigned scaled_cumul_prob = 0; + int nnz = 0; rac->prob[0] = 0; rac->prob[257] = UINT_MAX; @@ -164,6 +165,8 @@ static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb) prob = 256 - i; for (j = 0; j < prob; j++) rac->prob[++i] = 0; + }else { + nnz++; } } @@ -172,6 +175,10 @@ static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb) return -1; } + if (nnz == 1 && (show_bits_long(gb, 32) & 0xFFFFFF)) { + return AVERROR_INVALIDDATA; + } + /* Scale probabilities so cumulative probability is an even power of 2. */ scale_factor = av_log2(cumul_prob);