From patchwork Wed Oct 20 18:43:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 31178 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp1782620ioa; Wed, 20 Oct 2021 11:43:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpi+/mXeRvLbY2sTk4R282Lw2nfAdwMcV8/2NX/UNcDTX6b2phbDIp7RPm90VRBXM7K0Jl X-Received: by 2002:a05:6402:35d6:: with SMTP id z22mr816262edc.227.1634755431093; Wed, 20 Oct 2021 11:43:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634755431; cv=none; d=google.com; s=arc-20160816; b=chDhFT9f5qCK4ScY4HGb/64nUQoYpWp+DSW6JNr6b2uZY1iI11vkvfF1+EzjsOMEVN 5aclxJOgRmwEsaRSHhC3ECc3BEoXTeRuk2KWNf6YNFq6G0WWZfy21bMPZou09fPPfIDY evOuiV4YK3o+LYoGLpDRqNodhMBwa3ZzREfQpw9QhWDqCYTmVyVGPhlk3COIBR+pd2pT aYRI9RQv5tF+neH53yrPAKuPayRrTyO9g//0LQyoIIhrquYNTwb4EOWrGUfFcBj9wd+d kL5qTRqAFMsg6+Xwt5/lUbmwgD3pdv3EdTR5oFS3K87W8Maf02RdyZFwfwROwX8FUTEB 4G6A== 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:dkim-signature:delivered-to; bh=nYE/5XFwk5TxtQRaXQoNPxzo3N9s1ZHa3437l6Eubew=; b=VtdmoFpyxEQhMtL97VqOATvyVdJLpT+Ba88DtiDuezGNA8oD+4PMwBpip8KuAjjMSS 7/I7bgDrdg4m13djfI24ohUfeN4TKjFbflkAxrtiTjAfxLDxt2liWmn75hJ/PjrNqSlF CA6hSFoDPwTSUVkGyrwTENh4W1xyQ67ATVK+LCBgljopIayZXLPWPMFnDgklErlKDLs3 ZIyjK4p8y3fo07DK4L73TLBHk5rkrGqAALfEhMmoslzMIJWfXaRalq3Wh2fZskpvfsgw beSkwxnucLK7j1TFveia2RSjVsN0odRr3cKgJ5HMqqnYVhBpPuzYr4LydU4Ch+GWmQIe kQNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Uxo+6wi1; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f20si5285791edd.395.2021.10.20.11.43.50; Wed, 20 Oct 2021 11:43:51 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Uxo+6wi1; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D182468A94D; Wed, 20 Oct 2021 21:43:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4DE26680979 for ; Wed, 20 Oct 2021 21:43:40 +0300 (EEST) Received: by mail-wm1-f45.google.com with SMTP id g39so16480191wmp.3 for ; Wed, 20 Oct 2021 11:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZrevbeNin2oyvSSZhjfFtwR+arBHPwfDG3I45bx1rYU=; b=Uxo+6wi1kDXBmq5vxMr9rgPxJVIvHk3qLffB9bEvbYul9cxikoQObKxsWxVXxhZxvN y1d9JyNWE0C0YiCIRAOKWL1fg6yH0ZTQ8H7TxOD57Uv2n1mP7Yh/mgK9B7tPu26eCNoV D/gpbpYueTqV4s0XOCFdTWICAk1DwrQVzITXz0BxaakQ/PAVI4EcZdvGleiVd91AGf4S 8GC6N9bxPZIjFV7auLDVvFgvo/1UGsPRbguWKBttn0MjDPoT+zDPCKa3UKBvJBL/4V9Y 1XtQS72DUm76FCsjYKnnCvsvO/aJfNiLsuVc8YPFFtaGM9cNGZkNcRsomvLcuY2t89bu s2Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZrevbeNin2oyvSSZhjfFtwR+arBHPwfDG3I45bx1rYU=; b=RUQLWqOve7jFfzlmVgkAXa+AdMyDFELCaXq8xqan2kgQ+62hmF47K5GLdnxVU186eu bRDBxyhstiFLSWUd4pPIoEXXn+sTgwmtg9si+uA1f0PPBWcK3+utayiAzEh8j/t2FU/Y 1GxOIgNETGxj5VHfKO5rJzKDUkB5OvX2DzDJ6adDa/XUxTBD/x4Ns3Gbzd7D0mEQi8xi fjMKM9456Dv7GtPBAyAwZIqMfRM7yoSCvMStsaQvXxwqEV78OMze6nkpxqg4evtYPEd9 LaDlDnZxFk6QgyLqUfCEGql6ayJ5z/TgFLhXqRI3j5/30tpaRj4B5TiOB6lwdORgfZiR T/wg== X-Gm-Message-State: AOAM533+2yzs2RridCqwDW/lHkBgfLlCknBu1kzIcM+GMGPD9Q4XbOYi yKMf5JUm/CLJvEgmHu6v86wcqivRSYs= X-Received: by 2002:a7b:c088:: with SMTP id r8mr15695388wmh.120.1634755419573; Wed, 20 Oct 2021 11:43:39 -0700 (PDT) Received: from localhost.localdomain ([82.129.92.120]) by smtp.gmail.com with ESMTPSA id j16sm3195409wms.16.2021.10.20.11.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 11:43:39 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Wed, 20 Oct 2021 19:43:30 +0100 Message-Id: <20211020184330.1334724-1-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211020140354.1124965-1-derek.buitenhuis@gmail.com> References: <20211020140354.1124965-1-derek.buitenhuis@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2 v2] avformat/mov: Use av_rescale when calculating bit rate 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ifr43HV6F29X It is less susceptible to overflows. Signed-off-by: Derek Buitenhuis --- libavformat/mov.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 57c67e3aac..841818b547 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7989,12 +7989,14 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; if (st->duration > 0) { - if (sc->data_size > INT64_MAX / sc->time_scale / 8) { + /* Akin to sc->data_size * 8 * sc->time_scale / st->duration but accounting for overflows. */ + st->codecpar->bit_rate = av_rescale(sc->data_size, ((int64_t) sc->time_scale) * 8, st->duration); + if (st->codecpar->bit_rate == INT64_MIN) { av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %"PRId64" * 8 * %d\n", sc->data_size, sc->time_scale); + st->codecpar->bit_rate = 0; return AVERROR_INVALIDDATA; } - st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration; } } } @@ -8004,13 +8006,14 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; if (sc->duration_for_fps > 0) { - if (sc->data_size > INT64_MAX / sc->time_scale / 8) { + /* Akin to sc->data_size * 8 * sc->time_scale / sc->duration_for_fps but accounting for overflows. */ + st->codecpar->bit_rate = av_rescale(sc->data_size, ((int64_t) sc->time_scale) * 8, sc->duration_for_fps); + if (st->codecpar->bit_rate == INT64_MIN) { av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %"PRId64" * 8 * %d\n", sc->data_size, sc->time_scale); + st->codecpar->bit_rate = 0; return AVERROR_INVALIDDATA; } - st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / - sc->duration_for_fps; } } }