From patchwork Thu May 25 14:10:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 3734 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp818219vsk; Thu, 25 May 2017 07:11:43 -0700 (PDT) X-Received: by 10.28.236.205 with SMTP id h74mr9558981wmi.92.1495721503669; Thu, 25 May 2017 07:11:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495721503; cv=none; d=google.com; s=arc-20160816; b=csq9v5WoQIGqCP5XGA3lfQ1qkCvKbIcD9rYCARAOcXUPKr/8LnqOV1xJyvMcgXu3fz PuuuTFsjQAKQTAkqul/JANJL0eStOhy9pawan3yaOwIfNKemkw9D5aoyN2+u3ULsre9A yaiPyWgQ3xoUezwP3vOLIYkG+c8aIzxLKrH6p3pPEmNHtuIn7RxqLyHGqmIPTMWJS3/3 20fhAxgh8C3iD4/s6dQo0qgaGJc0VJP0ENyjf78XFAdb1jiFKV8FrL98caBVCN94Xf/j jIy8xhX1CnV3AqoysDQBkIsoYpTCmKyvzm6qIni0QhJpuNI/f0zC6rI3+oFezleTj4Xr qM2w== 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=XsdaDQWuT0lYBE4O7nm4/erHYyjJ2IshV5jRNsXd10Q=; b=ne2Z++tPKkeS/PdiVCRfIW5y10I/zGdszwezZJfyTxKsHfaVgofdL9Ygu8yh7BLxeS HElCasz3kVw058tqxH047Cf0uit5pPaWggST+JOSo4qFz0yxJxvAdnjWzTZRAzDV6OD5 BFdj2V1YeujugNKI29kA3BlffAp1Mz9A4tc0eMaJokpzM87hx27SjqJt6foyTIVTkx06 sJUSv0zNFxOQpChk9sy5zdb2bGzD+GKZ1tSvOYzFzvwQEZRGIGeZl5gZHcHu7VvvVKKP McQ1mMXyyxGKjjYQRb+K+2N2zHiIxroGhOjCts+C6BUGa8ljxwxQe/m4t+B2AvrThky0 MHNw== 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 b34si24429901wrb.130.2017.05.25.07.11.43; Thu, 25 May 2017 07:11:43 -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 78547689BE6; Thu, 25 May 2017 17:11:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe01-2.mx.upcmail.net (vie01a-qmta-pe01-2.mx.upcmail.net [62.179.121.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D50B8689999 for ; Thu, 25 May 2017 17:11:30 +0300 (EEST) Received: from [172.31.218.43] (helo=vie01a-dmta-pe05-1.mx.upcmail.net) by vie01a-pqmta-pe01.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dDtUC-0005Nn-QX for ffmpeg-devel@ffmpeg.org; Thu, 25 May 2017 16:11:32 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dDtU7-0006my-1u for ffmpeg-devel@ffmpeg.org; Thu, 25 May 2017 16:11:27 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id QeAp1v0190S5wYM01eAq05; Thu, 25 May 2017 16:10:50 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 25 May 2017 16:10:49 +0200 Message-Id: <20170525141049.23344-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.13.0 Subject: [FFmpeg-devel] [PATCH] avcodec/fft_template: Fix multiple runtime error: signed integer overflow: -1943918714 - 1935113003 cannot be represented in type 'int' 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: 1735/clusterfuzz-testcase-minimized-5350472347025408 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/fft_template.c | 50 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/libavcodec/fft_template.c b/libavcodec/fft_template.c index 480557f49f..e3a37e5d69 100644 --- a/libavcodec/fft_template.c +++ b/libavcodec/fft_template.c @@ -249,7 +249,7 @@ static void fft_calc_c(FFTContext *s, FFTComplex *z) { int nbits, i, n, num_transforms, offset, step; int n4, n2, n34; - FFTSample tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; + SUINT tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; FFTComplex *tmpz; const int fft_size = (1 << s->nbits); int64_t accu; @@ -260,14 +260,14 @@ static void fft_calc_c(FFTContext *s, FFTComplex *z) { offset = ff_fft_offsets_lut[n] << 2; tmpz = z + offset; - tmp1 = tmpz[0].re + tmpz[1].re; - tmp5 = tmpz[2].re + tmpz[3].re; - tmp2 = tmpz[0].im + tmpz[1].im; - tmp6 = tmpz[2].im + tmpz[3].im; - tmp3 = tmpz[0].re - tmpz[1].re; - tmp8 = tmpz[2].im - tmpz[3].im; - tmp4 = tmpz[0].im - tmpz[1].im; - tmp7 = tmpz[2].re - tmpz[3].re; + tmp1 = tmpz[0].re + (SUINT)tmpz[1].re; + tmp5 = tmpz[2].re + (SUINT)tmpz[3].re; + tmp2 = tmpz[0].im + (SUINT)tmpz[1].im; + tmp6 = tmpz[2].im + (SUINT)tmpz[3].im; + tmp3 = tmpz[0].re - (SUINT)tmpz[1].re; + tmp8 = tmpz[2].im - (SUINT)tmpz[3].im; + tmp4 = tmpz[0].im - (SUINT)tmpz[1].im; + tmp7 = tmpz[2].re - (SUINT)tmpz[3].re; tmpz[0].re = tmp1 + tmp5; tmpz[2].re = tmp1 - tmp5; @@ -288,19 +288,19 @@ static void fft_calc_c(FFTContext *s, FFTComplex *z) { offset = ff_fft_offsets_lut[n] << 3; tmpz = z + offset; - tmp1 = tmpz[4].re + tmpz[5].re; - tmp3 = tmpz[6].re + tmpz[7].re; - tmp2 = tmpz[4].im + tmpz[5].im; - tmp4 = tmpz[6].im + tmpz[7].im; + tmp1 = tmpz[4].re + (SUINT)tmpz[5].re; + tmp3 = tmpz[6].re + (SUINT)tmpz[7].re; + tmp2 = tmpz[4].im + (SUINT)tmpz[5].im; + tmp4 = tmpz[6].im + (SUINT)tmpz[7].im; tmp5 = tmp1 + tmp3; tmp7 = tmp1 - tmp3; tmp6 = tmp2 + tmp4; tmp8 = tmp2 - tmp4; - tmp1 = tmpz[4].re - tmpz[5].re; - tmp2 = tmpz[4].im - tmpz[5].im; - tmp3 = tmpz[6].re - tmpz[7].re; - tmp4 = tmpz[6].im - tmpz[7].im; + tmp1 = tmpz[4].re - (SUINT)tmpz[5].re; + tmp2 = tmpz[4].im - (SUINT)tmpz[5].im; + tmp3 = tmpz[6].re - (SUINT)tmpz[7].re; + tmp4 = tmpz[6].im - (SUINT)tmpz[7].im; tmpz[4].re = tmpz[0].re - tmp5; tmpz[0].re = tmpz[0].re + tmp5; @@ -311,13 +311,13 @@ static void fft_calc_c(FFTContext *s, FFTComplex *z) { tmpz[6].im = tmpz[2].im + tmp7; tmpz[2].im = tmpz[2].im - tmp7; - accu = (int64_t)Q31(M_SQRT1_2)*(tmp1 + tmp2); + accu = (int64_t)Q31(M_SQRT1_2)*(int)(tmp1 + tmp2); tmp5 = (int32_t)((accu + 0x40000000) >> 31); - accu = (int64_t)Q31(M_SQRT1_2)*(tmp3 - tmp4); + accu = (int64_t)Q31(M_SQRT1_2)*(int)(tmp3 - tmp4); tmp7 = (int32_t)((accu + 0x40000000) >> 31); - accu = (int64_t)Q31(M_SQRT1_2)*(tmp2 - tmp1); + accu = (int64_t)Q31(M_SQRT1_2)*(int)(tmp2 - tmp1); tmp6 = (int32_t)((accu + 0x40000000) >> 31); - accu = (int64_t)Q31(M_SQRT1_2)*(tmp3 + tmp4); + accu = (int64_t)Q31(M_SQRT1_2)*(int)(tmp3 + tmp4); tmp8 = (int32_t)((accu + 0x40000000) >> 31); tmp1 = tmp5 + tmp7; tmp3 = tmp5 - tmp7; @@ -348,10 +348,10 @@ static void fft_calc_c(FFTContext *s, FFTComplex *z) { offset = ff_fft_offsets_lut[n] << nbits; tmpz = z + offset; - tmp5 = tmpz[ n2].re + tmpz[n34].re; - tmp1 = tmpz[ n2].re - tmpz[n34].re; - tmp6 = tmpz[ n2].im + tmpz[n34].im; - tmp2 = tmpz[ n2].im - tmpz[n34].im; + tmp5 = tmpz[ n2].re + (SUINT)tmpz[n34].re; + tmp1 = tmpz[ n2].re - (SUINT)tmpz[n34].re; + tmp6 = tmpz[ n2].im + (SUINT)tmpz[n34].im; + tmp2 = tmpz[ n2].im - (SUINT)tmpz[n34].im; tmpz[ n2].re = tmpz[ 0].re - tmp5; tmpz[ 0].re = tmpz[ 0].re + tmp5;