From patchwork Thu Jul 13 22:45:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 4317 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp192044vsb; Thu, 13 Jul 2017 15:45:57 -0700 (PDT) X-Received: by 10.28.104.132 with SMTP id d126mr564257wmc.49.1499985957207; Thu, 13 Jul 2017 15:45:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499985957; cv=none; d=google.com; s=arc-20160816; b=iV0hjP0hLwcNn9wLNKRUGhEwZFqmOx2BKJegVUl62b32AwNRWD/B3bpn1hqu69JJq1 mZ5Lm3PTFcZziDdm1DwKiFkufGhEau6CxiEfQrRGPXJ/HJ638Woj8mbLeU6sSXH974Tn 9o9wsYuhqn2xNwGllB8rJ0pHVNcaHGte+HJBEftTZvuGO0ZO4P8/ndKQFovRKiehxjVS YTvPui8jgCExVKwdM4wiEe3YmchvYkQQHp+q7m3z0nJv35Ao2PBV95eJF3KHoGjgIbjn 0Lb1MxnY3Ajtb3O11n+UBxJiZHN3vmVo3g31JI2+FBBCDemODzTJAyQmUlKjLe/LxJgV CmMg== 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=ohPkdcqmLygoyX5ZMrVw9NmyTgG//Cxo6EGux4sGU6I=; b=X6jNCHcQXhtPbRmPgCfJGQD816AGUzvRXGMg/XLrNf2Ozq9vKYqU0WupciHA/pxjnz 3TyFarIV4ZdJZeAaMGWdUhVYxyUrMU43e+XuRhCSswGnoaNRppxYvb7lbkPptCXnetvi SWVp9up/va8rcpqKpcu+g2X0t6W614TrWAKeIJur71Tmn8WzPHfiRKuAr3lLNEzjCFze 2XKcw7jRFxg8kCPMoeY+0yeVImRoKR879HSwHIwPq3tFJ2c5tPJvklRXNkmBX3A/1xav MGLyyrqmQ/jshSnC3cTLX0rcmUxAvc1LejsnXD3ydnvIoFrfiAqe8102ZuqvTkZI6Eia 5mfA== 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 k62si541928wmb.117.2017.07.13.15.45.56; Thu, 13 Jul 2017 15:45:57 -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 314886882DB; Fri, 14 Jul 2017 01:45:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-2.mx.upcmail.net (vie01a-qmta-pe02-2.mx.upcmail.net [62.179.121.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3DFB66882DB for ; Fri, 14 Jul 2017 01:45:42 +0300 (EEST) Received: from [172.31.218.52] (helo=vie01a-dmta-pe05-1.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dVmrj-0007xH-8N for ffmpeg-devel@ffmpeg.org; Fri, 14 Jul 2017 00:45:47 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe08.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dVmrc-0006QU-Bf for ffmpeg-devel@ffmpeg.org; Fri, 14 Jul 2017 00:45:40 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id kNlW1v00K0S5wYM01NlXJZ; Fri, 14 Jul 2017 00:45:31 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 14 Jul 2017 00:45:29 +0200 Message-Id: <20170713224529.10484-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.13.0 Subject: [FFmpeg-devel] [PATCH] avcodec/aacdec_template: Fix undefined integer overflow in apply_tns() 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: signed integer overflow: -2147483648 - 1202286525 cannot be represented in type 'int' Fixes: 2071/clusterfuzz-testcase-minimized-6036414271586304 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/aac_defines.h | 2 ++ libavcodec/aacdec_template.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libavcodec/aac_defines.h b/libavcodec/aac_defines.h index 3c79a8a4a1..438d78a7aa 100644 --- a/libavcodec/aac_defines.h +++ b/libavcodec/aac_defines.h @@ -35,6 +35,7 @@ #define AAC_RENAME(x) x ## _fixed #define AAC_RENAME_32(x) x ## _fixed_32 typedef int INTFLOAT; +typedef unsigned UINTFLOAT; ///< Equivalent to INTFLOAT, Used as temporal cast to avoid undefined sign overflow operations. typedef int64_t INT64FLOAT; typedef int16_t SHORTFLOAT; typedef SoftFloat AAC_FLOAT; @@ -83,6 +84,7 @@ typedef int AAC_SIGNE; #define AAC_RENAME(x) x #define AAC_RENAME_32(x) x typedef float INTFLOAT; +typedef float UINTFLOAT; typedef float INT64FLOAT; typedef float SHORTFLOAT; typedef float AAC_FLOAT; diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 4cbbc6023a..c60a6ca096 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -2389,7 +2389,7 @@ static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, * @param decode 1 if tool is used normally, 0 if tool is used in LTP. * @param coef spectral coefficients */ -static void apply_tns(INTFLOAT coef[1024], TemporalNoiseShaping *tns, +static void apply_tns(INTFLOAT coef_param[1024], TemporalNoiseShaping *tns, IndividualChannelStream *ics, int decode) { const int mmm = FFMIN(ics->tns_max_bands, ics->max_sfb); @@ -2397,6 +2397,7 @@ static void apply_tns(INTFLOAT coef[1024], TemporalNoiseShaping *tns, int bottom, top, order, start, end, size, inc; INTFLOAT lpc[TNS_MAX_ORDER]; INTFLOAT tmp[TNS_MAX_ORDER+1]; + UINTFLOAT *coef = coef_param; for (w = 0; w < ics->num_windows; w++) { bottom = ics->num_swb; @@ -2426,7 +2427,7 @@ static void apply_tns(INTFLOAT coef[1024], TemporalNoiseShaping *tns, // ar filter for (m = 0; m < size; m++, start += inc) for (i = 1; i <= FFMIN(m, order); i++) - coef[start] -= AAC_MUL26(coef[start - i * inc], lpc[i - 1]); + coef[start] -= AAC_MUL26((INTFLOAT)coef[start - i * inc], lpc[i - 1]); } else { // ma filter for (m = 0; m < size; m++, start += inc) {