From patchwork Wed Oct 10 23:45:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 10626 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:ab0:73d2:0:0:0:0:0 with SMTP id m18csp1462566uaq; Wed, 10 Oct 2018 16:49:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV63IFEWxQ9FxewB2x6kWAdTD+a3Rg5VEypYw/SjOS7TzlHISm27hxeKnKjdKIQPBZVgQnlK+ X-Received: by 2002:a1c:7a0a:: with SMTP id v10-v6mr2529299wmc.41.1539215355881; Wed, 10 Oct 2018 16:49:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539215355; cv=none; d=google.com; s=arc-20160816; b=FXPEeQ9CYeEkPXZaJSqxO75sNniLdvI0EmH6YX02ENd3TMpkwxa2X11phitl83YyxB H8bSMpPPxNaCuFmmB71c5k3kUur5/4rxbW2oMb6q3Aox1hhRH2m6GWt2FWOxBUM+LNK9 tD+Psv6SNvsl+4WFaCaNILcqCPbsfTFCAodGGlfXAK1fqpeHtOdSiJ1rKvpi5VpxXDpr VmQ3NKP7N6IXnXG2qg1j8pIo3zrbwF8AM28cPTU7EdMAT864jNNRHYFL4hULMOqghC2U RKKzZ12aNaskMFVTuMbgB46s/tPApRAtRT8TP/BQ59gmEfylbnAQZDLLo9nQcKubw9u+ EJ6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=8z+N5lwFNIpTDGoS7fQCs7zjo4LZ3yE7WcUv6ETDwT4=; b=ENE/CINlzANB1obPA2h7rYfXNj3KlqKTxSHKd9M3uDQdrRAx3n2Y5uC8MILgpUR4tD Yt4Ubg1Go8QuJNCjCMaCedd7sgXO0+01Q3SCyF/rcIDh6HVdQ5ft0N7qZB3HdU+5A/sz A8YziC1FqmrsErsWKXjRU0IA1x+5S2irnIQnFkDN1Hr/g/oCWUsss2IjJ6YJQTBhgVCF Cc+/MOqgeY5hQUkQSKFLhm4KrMh3j4RPJh8xPedw/R2WMLF2eUh8DYHTKoKIUCKKhymv CB1l5EWamc+VzCQfD4WlEUN8c/V1bKqMPUSzYKjIIHYQ2nmC+/tIi+yzONubK0EETA9T q2sw== 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 81-v6si14906543wmj.182.2018.10.10.16.49.15; Wed, 10 Oct 2018 16:49:15 -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 BFFED68A190; Thu, 11 Oct 2018 02:48:40 +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 C8D0068A145 for ; Thu, 11 Oct 2018 02:48:39 +0300 (EEST) Received: from [172.31.218.46] (helo=vie01a-dmta-pe06-1.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1gAODt-0001DI-VN for ffmpeg-devel@ffmpeg.org; Thu, 11 Oct 2018 01:49:01 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1gAODo-0002De-Hf for ffmpeg-devel@ffmpeg.org; Thu, 11 Oct 2018 01:48:56 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id lzoo1y00K0S5wYM01zopV0; Thu, 11 Oct 2018 01:48:49 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 11 Oct 2018 01:45:32 +0200 Message-Id: <20181010234532.5857-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181010234532.5857-1-michael@niedermayer.cc> References: <20181010234532.5857-1-michael@niedermayer.cc> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/ilbcdec: Fix multiple integer overflows 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: 10651/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ILBC_fuzzer-5202341540659200 Fixes: signed integer overflow: -1707705920 - 1703592888 cannot be represented in type 'int' This tries to follow the webrtc code. For example using cliping and 64 bit as in WebRtcSpl_DotProductWithScale() and not doing so in other places. I could not find anything in rfc3951 and the reference code inside which would explain what to do in these corner cases. Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/ilbcdec.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavcodec/ilbcdec.c b/libavcodec/ilbcdec.c index 58044f4ba8..8f234b98e1 100644 --- a/libavcodec/ilbcdec.c +++ b/libavcodec/ilbcdec.c @@ -381,7 +381,7 @@ static void get_lsp_poly(int16_t *lsp, int32_t *f) tmp = ((high * lsp[k]) * 4) + (((low * lsp[k]) >> 15) * 4); f[l] += f[l - 2]; - f[l] -= tmp; + f[l] -= (unsigned)tmp; } f[l] -= lsp[k] * (1 << 10); @@ -402,16 +402,16 @@ static void lsf2poly(int16_t *a, int16_t *lsf) get_lsp_poly(&lsp[1], f[1]); for (i = 5; i > 0; i--) { - f[0][i] += f[0][i - 1]; - f[1][i] -= f[1][i - 1]; + f[0][i] += (unsigned)f[0][i - 1]; + f[1][i] -= (unsigned)f[1][i - 1]; } a[0] = 4096; for (i = 5; i > 0; i--) { - tmp = f[0][6 - i] + f[1][6 - i]; + tmp = f[0][6 - i] + (unsigned)f[1][6 - i]; a[6 - i] = (tmp + 4096) >> 13; - tmp = f[0][6 - i] - f[1][6 - i]; + tmp = f[0][6 - i] - (unsigned)f[1][6 - i]; a[5 + i] = (tmp + 4096) >> 13; } } @@ -508,10 +508,10 @@ static void filter_arfq12(const int16_t *data_in, int output = 0, sum = 0; for (j = coefficients_length - 1; j > 0; j--) { - sum += coefficients[j] * data_out[i - j]; + sum += (unsigned)(coefficients[j] * data_out[i - j]); } - output = coefficients[0] * data_in[i] - sum; + output = coefficients[0] * data_in[i] - (unsigned)sum; output = av_clip(output, -134217728, 134215679); data_out[i] = (output + 2048) >> 12; @@ -901,12 +901,12 @@ static int16_t get_size_in_bits(uint32_t n) static int32_t scale_dot_product(const int16_t *v1, const int16_t *v2, int length, int scaling) { - int32_t sum = 0; + int64_t sum = 0; for (int i = 0; i < length; i++) sum += (v1[i] * v2[i]) >> scaling; - return sum; + return av_clipl_int32(sum); } static void correlation(int32_t *corr, int32_t *ener, int16_t *buffer,