From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id D9ECF44316 for ; Sat, 6 May 2023 15:18:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 207BC68C13B; Sat, 6 May 2023 18:18:02 +0300 (EEST) Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E511768C13B for ; Sat, 6 May 2023 18:17:55 +0300 (EEST) Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-192b330a577so1187086fac.3 for ; Sat, 06 May 2023 08:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683386274; x=1685978274; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JJeulz9xpOhnyfRLmxIgFAN7nPRl+bNSzhpebSJs1d0=; b=Yylv/FtBHuiPoiyELDB5xsToklJ0GqQg/ZeSIp4g4LCHb1cYMGaBWdqjl7mWTPaLYN JQzJC6cSBJ0vVMFnRsLWi5n3mgjpXXZlzgc/SGH1NmwKGM++CbkZDtcrhk+pJo/awO0H o0gETjhKF0FT4+zpPIGLgEt579cljK+fC7TuY77W/Zbzd3iN45dWC1Pverx2WVMy7oBp eIqkzXm7khk00VGHCQ6daxneychsTmVtiEo4ot2CkwQbgqyzycdDPrTUtQbTNClSMmD9 AnOqrS+K0rCFGlD3wdfy7QFGMtqOUNKD+3EyMAe/BYh9lvJ/TdrtRN/Zj6DkAq6TEPp/ Hc6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683386274; x=1685978274; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JJeulz9xpOhnyfRLmxIgFAN7nPRl+bNSzhpebSJs1d0=; b=DYwb16QqPbRJYLO6CPqPemudRu0Jj2Lk1I5McTRm64EQVFl1SZxp17B1vxBo+iT9mV Tf2kio4M3f6/r/twC8FFNQGBu4mZAFNwsXYrdkIlsFuGzRLgqV4iAuwTIMgz5/ewzZWQ AW6zwH1fYC0dvPZ1lU218cXlu+KiUFoxeBC+kg3opdQCfzjYrG0zePGcHOiKg7/MPoMl xadqIGAO1D/HwX9XLe0mQgkAN9F4fXZshWZNiUKgSGb6Us/N+o3koL9YWR0mir1ek1kg ZUshHUYYBHWur2RghrV6Zod6BsjETIJ9UaCY0l/yPbfb8AGu4q0CwspfB0bBBRKKJbdw V9Wg== X-Gm-Message-State: AC+VfDxFgyCcU8KVioKg1QVCLEkftR7QoqdaUXVXt8ZzY0cb/yNGloNR 9CubkYKsLCbp3RtJll75Lw+cyg5gLvM= X-Google-Smtp-Source: ACHHUZ68lae2JyAbDQZO9ywbZcCTjcqfY3j1I89g1OITifjf1+R0m/n60HC9VCLpc3hdz2ubEz1epg== X-Received: by 2002:a05:6870:42d3:b0:187:7c2b:edc7 with SMTP id z19-20020a05687042d300b001877c2bedc7mr3237524oah.15.1683386273766; Sat, 06 May 2023 08:17:53 -0700 (PDT) Received: from [192.168.0.12] (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id h1-20020a056870a3c100b0018b9dc6acaasm3110980oak.34.2023.05.06.08.17.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 May 2023 08:17:53 -0700 (PDT) Message-ID: Date: Sat, 6 May 2023 12:18:00 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20230416164830.15664-1-michael@niedermayer.cc> <20230416164830.15664-5-michael@niedermayer.cc> <20230506150813.GD4538@pb2> From: James Almer In-Reply-To: <20230506150813.GD4538@pb2> Subject: Re: [FFmpeg-devel] [PATCH 05/11] avcodec/flacdec: Fix signed integre overflow X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 5/6/2023 12:08 PM, Michael Niedermayer wrote: > On Fri, May 05, 2023 at 07:36:05PM -0300, James Almer wrote: >> On 4/16/2023 1:48 PM, Michael Niedermayer wrote: >>> Fixes: signed integer overflow: 3011809745540902265 + 6323452730883571725 cannot be represented in type 'long' >>> Fixes: 45982/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FLAC_fuzzer-6687553022722048 >>> >>> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg >>> Signed-off-by: Michael Niedermayer >>> --- >>> libavcodec/flacdec.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c >>> index cc778a8dff1..524a0469495 100644 >>> --- a/libavcodec/flacdec.c >>> +++ b/libavcodec/flacdec.c >>> @@ -513,7 +513,7 @@ static int decode_subframe_lpc_33bps(FLACContext *s, int64_t *decoded, >>> for (i = pred_order; i < s->blocksize; i++, decoded++) { >>> int64_t sum = 0; >>> for (j = 0; j < pred_order; j++) >>> - sum += (int64_t)coeffs[j] * decoded[j]; >>> + sum += (int64_t)coeffs[j] * (uint64_t)decoded[j]; >> >> Why not instead do >> >> sum = av_sat_add64(sum, (int64_t)coeffs[j] * decoded[j]); > > Why should this be clipping ? > flac is a lossless codec, i see nothing in the specification that calls for > cliping. No, but an overflowing case like 3011809745540902265 + 6323452730883571725 isn't supported either and will generate bad output, so might as well use an optimized function for this. > > >> >> Also, decoded[j] is an int64_t, so wouldn't coeffs[j] be promoted if you >> swap the order in the multiplication, thus saving the cast? > > it can be shuffled around to achieve the same, do you prefer > coeffs[j] * (uint64_t)decoded[j]; ? No gain doing that compared to your first version. I suggested it for av_sat_add64(), which i insist you should use, if you want with a comment about it being there not for spec reasons but to prevent integer overflows, and removing all casts. > > thx > > [...] > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".