From patchwork Thu Dec 15 00:53:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Cadhalpun X-Patchwork-Id: 1793 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.86 with SMTP id o83csp475253vsa; Wed, 14 Dec 2016 17:00:41 -0800 (PST) X-Received: by 10.28.93.202 with SMTP id r193mr10254972wmb.30.1481763641083; Wed, 14 Dec 2016 17:00:41 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f124si10022062wmd.64.2016.12.14.17.00.40; Wed, 14 Dec 2016 17:00:41 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@googlemail.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; dmarc=fail (p=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E459468922F; Thu, 15 Dec 2016 03:00:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8B127687EEF for ; Thu, 15 Dec 2016 03:00:25 +0200 (EET) Received: by mail-wm0-f65.google.com with SMTP id m203so2879242wma.3 for ; Wed, 14 Dec 2016 17:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:subject:to:references:message-id:date:user-agent:mime-version :in-reply-to; bh=ZlqON9K6GyBz94C/CYj0yFPgFwjCSBsC8B5PbhZmkYM=; b=l4FCa10mtYq+AiTDVb/jh4gCzPnyGlnfAUAR0QJPc++q+ijjTnYAHnIPc2RZ/QKZ3f uah+rRNaRiBZljQLV+pDbi6qW+7pMsnpxf+/wwQJKdicJj2Cmkryjm6SmpiMLSEMJyOg Wu3EFVD9RIwltq3JNbupE+2XOAvyOCRj5C6hDuxlYA75Z8i4jmhEAMX35nzqc9Nru+gq 1xljamPV1D/Vk1FKwHmpc5egN9LmCxYoPbLe0xyW5Bh87dZLgXsy/FlWkrPt652FYdcs OXQ7tYOdMNe+/iSeNrMb05V6zgwAHm8ASed7alCbff4M5Wzabaa3EizqqprXzL9Kr+Yj /Xmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to; bh=ZlqON9K6GyBz94C/CYj0yFPgFwjCSBsC8B5PbhZmkYM=; b=FP7pgX85T+FCibQkuMOicx+SawehGfAAOhnt5P90SSls8n9/cDrJetf59IIMM9lMIO LYTd0+APbX2pJi2TdEHNsOP/Z4fVBD6ekv5Hn7BsHWMlDFlCuBYRwK6iugl5HNrkDGfC d2CKAn1MZ3PYFpOFsc1VwYGQw5j0SCne2S+Q/JE0DjlKOlLA29jWe48p8RXWjlV+gL+s Y63JgAKwQa4wKP7k/zhgtCedmv1jZGDfgzZvMUFSota51fVtQ8SaoUCpCDvdcgG0XKqx Cypg4fLwDfTRIOPNQDzPqh3sjmVp4BmWxoTDQRRVLTn35b/JrUF4rSKaO19u1mIfjnZ3 mwsg== X-Gm-Message-State: AIkVDXI6b97LpzwF4uXdFyZS8uOtGuFJUESbqxW0uV0boXjUpeYd0d8Yyrn1HoUh9m62eg== X-Received: by 10.28.183.215 with SMTP id h206mr127893wmf.60.1481763204243; Wed, 14 Dec 2016 16:53:24 -0800 (PST) Received: from [192.168.2.21] (p5B095A24.dip0.t-ipconnect.de. [91.9.90.36]) by smtp.googlemail.com with ESMTPSA id x188sm9999206wmx.4.2016.12.14.16.53.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Dec 2016 16:53:23 -0800 (PST) From: Andreas Cadhalpun X-Google-Original-From: Andreas Cadhalpun To: ffmpeg-devel@ffmpeg.org References: <18a6d792-ed50-8963-ccfd-8c585824682f@googlemail.com> <8e0e442f-d2b2-618d-2f4f-123a4069b6d1@googlemail.com> <20161214101603.GA8115@sunshine.barsnick.net> Message-ID: Date: Thu, 15 Dec 2016 01:53:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161214101603.GA8115@sunshine.barsnick.net> Subject: Re: [FFmpeg-devel] [PATCH 1/3] omadec: fix overflows during bit rate calculation 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" On 14.12.2016 11:16, Moritz Barsnick wrote: > On Wed, Dec 14, 2016 at 01:02:41 +0100, Andreas Cadhalpun wrote: >> On 13.12.2016 08:11, Paul B Mahol wrote: >>>> - st->codecpar->bit_rate = samplerate * framesize * 8 / 2048; >>>> + st->codecpar->bit_rate = samplerate * framesize / 256; >> >> Why multiply with 8 when dividing by a multiple of 8 directly afterwards? >> That's just a waste of computational resources. > > I can only explain the term with "readability" (e.g. "number of bytes > times 8 is number of bits, divided by 2048 is the rate"). If you > bracket the (8 / 2048), it would avoid the overflow, and the compiler > should evaluate the term to that constant 256 anyway, right? (Just if > anyone cares about the presumed readability.) Well, (8 / 2048) = 0, but one can do "/ (2048 / 8)". Attached is a version doing it that way. Do you think that's better? Best regards, Andreas From 6bf8af5e8db1986ec1e30143a088b91041eb9ead Mon Sep 17 00:00:00 2001 From: Andreas Cadhalpun Date: Tue, 13 Dec 2016 00:35:12 +0100 Subject: [PATCH] omadec: fix overflows during bit rate calculation Signed-off-by: Andreas Cadhalpun --- libavformat/omadec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/omadec.c b/libavformat/omadec.c index 6e476db..757ae53 100644 --- a/libavformat/omadec.c +++ b/libavformat/omadec.c @@ -365,7 +365,7 @@ static int oma_read_header(AVFormatContext *s) st->codecpar->channels = 2; st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; st->codecpar->sample_rate = samplerate; - st->codecpar->bit_rate = st->codecpar->sample_rate * framesize * 8 / 1024; + st->codecpar->bit_rate = st->codecpar->sample_rate * framesize / (1024 / 8); /* fake the ATRAC3 extradata * (wav format, makes stream copy to wav work) */ @@ -398,7 +398,7 @@ static int oma_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } st->codecpar->sample_rate = samplerate; - st->codecpar->bit_rate = samplerate * framesize * 8 / 2048; + st->codecpar->bit_rate = samplerate * framesize / (2048 / 8); avpriv_set_pts_info(st, 64, 1, samplerate); break; case OMA_CODECID_MP3: -- 2.10.2