From patchwork Sat May 20 21:01:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 3705 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp827022vsk; Sat, 20 May 2017 14:01:25 -0700 (PDT) X-Received: by 10.223.160.139 with SMTP id m11mr6153703wrm.99.1495314085771; Sat, 20 May 2017 14:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495314085; cv=none; d=google.com; s=arc-20160816; b=mahi2kgtMkEnlyDBNvmWvZJZWdJoZerj4UZ/PwgKYwjONO69hMR7Il4vfvaztaUcTy 0XmFslqTT8bQN+wd+naXoLB17a5jhLv+LnRiOtmJHHHBKsOifeWD2CvXy5PF6ON4QNb+ kjKq2O63XR8XojDpQe4Zls9iPzKOaB+sfgYlxVeUDxuR3Yu/Pk5Gl9uj3gSJPBWQMroi NtDtm8Va9y/30mpdl6D+rzeDgk/CHWY4Vm+64rqGKPbHA+siBx2YH1+bMNMLzNYd1Kzh zSOOJIM/GL+/f/yelEDVyJst+OSVr5Ihbg+gpz7N58URgkI+LNZvLXcCt6LNX4wUYZun yCIQ== 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=rPi8UdY9/3m8XCeT+IpRkgN1zCiruA2iYtDkrb193eM=; b=VCWj4eJeYeWmutUkgA7Is30GvEKHaXPD4Z9l3+9ejVhtyVSEhZa6Q41tc94PAF2o2W 5N7OHFlS2wf657/NKQnBfXjqthPR92m2xLjKqTfLwBoKWe01VBr1wQZrRBflWYXFQwlY SQ327uOjnTyNZJ7Nk+vRzdZ/9/v0/5QGt9ZEjXhPns/hNzZW3U7AwKXY91Fq9PpmMEhr tN5W3o0z+L/vmWrxEe0Bzq9aO+4IikTiFWxz7bAihMr56meWsibD87nuDqI/kxod8SEI IN2pxqU8okPFfFOOUIUtFv87/yMErutQJpUSqZH9oYiAcZSEYW337rmi0hlF3XX9zsp2 xdYg== 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 i8si7394424wrb.99.2017.05.20.14.01.25; Sat, 20 May 2017 14:01:25 -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 924056899DF; Sun, 21 May 2017 00:01:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe03-1.mx.upcmail.net (vie01a-dmta-pe03-1.mx.upcmail.net [62.179.121.160]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 472E2689975 for ; Sun, 21 May 2017 00:01:14 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dCBUw-00021W-Ej for ffmpeg-devel@ffmpeg.org; Sat, 20 May 2017 23:01:14 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id Nl171v00c0S5wYM01l18k6; Sat, 20 May 2017 23:01:08 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 20 May 2017 23:01:04 +0200 Message-Id: <20170520210104.4943-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170520210104.4943-1-michael@niedermayer.cc> References: <20170520210104.4943-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/mlpdec: Check quant_step_size against huff_lsbs 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" This reorders the operations so as to avoid computations with the above arguments before they have been initialized. Fixes part of 1708/clusterfuzz-testcase-minimized-5035111957397504 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/mlpdec.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c index c0a23c5f0d..11be380d27 100644 --- a/libavcodec/mlpdec.c +++ b/libavcodec/mlpdec.c @@ -825,8 +825,6 @@ static int read_channel_params(MLPDecodeContext *m, unsigned int substr, return AVERROR_INVALIDDATA; } - cp->sign_huff_offset = calculate_sign_huff(m, substr, ch); - return 0; } @@ -838,7 +836,8 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, { SubStream *s = &m->substream[substr]; unsigned int ch; - int ret; + int ret = 0; + unsigned recompute_sho = 0; if (s->param_presence_flags & PARAM_PRESENCE) if (get_bits1(gbp)) @@ -878,19 +877,36 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, if (s->param_presence_flags & PARAM_QUANTSTEP) if (get_bits1(gbp)) for (ch = 0; ch <= s->max_channel; ch++) { - ChannelParams *cp = &s->channel_params[ch]; - s->quant_step_size[ch] = get_bits(gbp, 4); - cp->sign_huff_offset = calculate_sign_huff(m, substr, ch); + recompute_sho |= 1<min_channel; ch <= s->max_channel; ch++) - if (get_bits1(gbp)) + if (get_bits1(gbp)) { + recompute_sho |= 1<max_channel; ch++) { + if (recompute_sho & (1<channel_params[ch]; + + if (cp->codebook > 0 && cp->huff_lsbs < s->quant_step_size[ch]) { + if (ret >= 0) { + av_log(m->avctx, AV_LOG_ERROR, "quant_step_size larger than huff_lsbs\n"); + ret = AVERROR_INVALIDDATA; + } + s->quant_step_size[ch] = 0; + } + + cp->sign_huff_offset = calculate_sign_huff(m, substr, ch); + } + } + return ret; } #define MSB_MASK(bits) (-1u << (bits))