From patchwork Wed Oct 20 14:03:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 31168 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp1510404ioa; Wed, 20 Oct 2021 07:04:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/z3MtdS3FAG2uPr5Hg+ObsFP/gSwLU7V+duCs5VnST3IVYVrLs+cTBgnQflpVsXwV8kUj X-Received: by 2002:a17:907:6da3:: with SMTP id sb35mr27246632ejc.519.1634738671184; Wed, 20 Oct 2021 07:04:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634738671; cv=none; d=google.com; s=arc-20160816; b=sB5Njfh4EJK7p5Ihb1b7iYzCXlR3sfZm835PserNVWMGUcHg1Ds5S1bEXN5k71E/QL QaSnvUQzJAwAmv1o8bgIMCwkX2yDejUEp/ew3//8hANLzj52HLrNVKRtZcFxBa2Q4naL olcIuDderfrNZwRH8Z4TO7uA80zjw9zysLd48UoYlEa3kh4567u+mysLlZ5N4kCWQJe+ KjnZXyxJ/Nbs930lTsI2imGOmP8pnLwL05JG2Sz7fM/kNYXPs2DG2ALL+JoY/MiWEvmW N8iDt09ja7ZxgfhrVwS1nV5T9oN64r2e+wvCHi1330ZhffeVia9swk/0nQnhIUTxAs7P azqw== 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=uA0hP+7Y6oLhrTPhwEHM7uvMQDQ5R0oZI2BU3hEINxw=; b=od5ovrhRXgcbdDiJ2j3C76cmkwMxp1Yohi2VWZnfi/8fvePIm/SM9w2AP43BpK4lSa 99aRgtXcwJ35q1DoatW4OAz8DCv2flh3lSBuj9BAv7FZJWKm5pMy8D6RMqqTmgstu/xL e0/UYNglew5SWe2Wkh2W+W+z0UHWbAlQa6nnLks/1/4ThErpaFIZhgv+EAOAxf+Val4F KjFTdDSe9Uny3FmHz3o1QH8fcI/Azl+GUw6vt+/7rgRIJeaAfqn43M5m6ktU9GOXBEsV X+djflbtTyRYSza0p1qnX6pOTzCtfVagrYp8TXx2CQe9hjcB9rWIk6B7QsBGeDW0bzjX cGTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=h0KKd69g; 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 kq16si2880029ejb.521.2021.10.20.07.04.30; Wed, 20 Oct 2021 07:04:31 -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=h0KKd69g; 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 379DE68A7C0; Wed, 20 Oct 2021 17:04:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B298068A75A for ; Wed, 20 Oct 2021 17:04:06 +0300 (EEST) Received: by mail-wm1-f41.google.com with SMTP id g2so19284966wme.4 for ; Wed, 20 Oct 2021 07:04:06 -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=FbAjCRSehtxddd5N2NX7fndCFA/JicAc6kPJngbfKWo=; b=h0KKd69gmkxoQg21bq2CuS2wEbY3jh3a2aDx4CxUu7I7sQZrWFTVAO3ejlZ5h/EJE7 SPxM9LgiB/Gc2Ul7sS4rakqag2xZ8hFnM2MtLA9MJ/W8PTn5v3nszY+/nFQcTGwoAwQz Zd1ItYUovpMoH0YPqtDc3SxqXFrmcT/Dj/h7HIA8Q++pJnSivy2h+rY/2gyH6MPHp/7j hOjHyJq+CTux6BHT++t/sP2YRAO8cSRokhvelUoPlpa46g1wUdsczcITEkp2ox8Yf+8C PJcihbJaC+XA5/Z9Y8DIjdaz2MYXyuXhhVfKNYuvvWxIEJaTem+2Wr3Z6DEMr8TxlIlt 0KzA== 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=FbAjCRSehtxddd5N2NX7fndCFA/JicAc6kPJngbfKWo=; b=45ys2vlyPMuP1+LW0hUFn+a16dsxDBd+6/MGjc7ssovMWfsluKxMrG/DZzhOHreyeD cK2f3ce4rhu3mMNcdtyUDY5US0BfM62ba7adQAeP8iDfOnX8OteYX9FMwXiHXNTc8SVo C/rDsMcTsVCjl15wtm4z+jwHCUztqacabVvtP//Gr9FdnVsr1xBXybMdgn7o/IUcjn97 co+aJKFSeVbpsNUe6YSu4X2P+UL3Lrd8Og75auCL4YDOPIfc4X0JRHceBmoUlBLQkhA5 pji164ferdcHpmLfZLNEI+IZ2JXYk5CrWpdfGBj2e2WkPqxvLM3P9A4DIk2CFG0C7SHb en9g== X-Gm-Message-State: AOAM532D7hO2d5YNyuN9Yh+tp9SEhxu4eX1xa+IY26lG77FFTPq8JwbQ gb/JUpX7eARnhXJFoQHddRkzdRXGMqc= X-Received: by 2002:adf:a48e:: with SMTP id g14mr52614769wrb.11.1634738645772; Wed, 20 Oct 2021 07:04:05 -0700 (PDT) Received: from localhost.localdomain ([82.129.92.120]) by smtp.gmail.com with ESMTPSA id l40sm2222743wms.31.2021.10.20.07.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 07:04:05 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Wed, 20 Oct 2021 15:03:53 +0100 Message-Id: <20211020140354.1124965-2-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] 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: 8fJl3qKgLSVj 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..431f430368 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, 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, 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; } } } From patchwork Wed Oct 20 14:03:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 31167 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp1511085ioa; Wed, 20 Oct 2021 07:05:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygQIl9/o9Ygpzs3xngnr1lV1cddmqpVwihez5QYwaV65Qle3cQSUxlGA7HRs90yO5cbfOa X-Received: by 2002:a17:906:94da:: with SMTP id d26mr47266013ejy.213.1634738685803; Wed, 20 Oct 2021 07:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634738685; cv=none; d=google.com; s=arc-20160816; b=xClwjwnylobIFSrQuHYo2UyEe/0tNUxK+B2vElqgHp1/AIsLLO5gONTuc91KuB2WY+ 70RB3q1o0ToeEhxuCUWDENaLNSd+4pFciYGhfYo3jDNeNeJi2nDKzQhNAOWA9xUk5BRl n7DPFP/9Lc7kO44jVO8Hcwf4e/Hh1XXVuf07iQLz0MAtQlOs1dLv8tSr+IfWrSH7ssVe kjIclyitxdkmcMIX6RVi8gHv5EdUrUvrIMR4uWQmPJk35RfTkZewdWuZc87H4D/Gq8I7 aMYrZfsLNOCZyfR1SGDQ/Sj0XBCMkVC9jqiKITWEqgMdSbKaCYVth2m3PKqya5b0/zL1 +jBQ== 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=PvovLoa/BXfxQLqVnQsUJW7QDOZR0HTF2DR+teNFJWo=; b=uyNiNmJqSgxoCOYPO0t3/b0KGS+xJFe1zHLpH29Msv0oFujGI+ZfVTLbzi5XfBGIiu DWukH3AsRgw/jiiyDkTBUfqjPhENY6f4GUvyHLIAM/oXfVnchm99hI12dCQdSdWr74QT ujy1Megt2UBJN0wt49yWY4H3FIKF+/66pYJ5d+sClBkfcsjb79LGdIEJsKd+Coigjyyf 2KTtMvbVGyHRg9pKvd6naNCNDwPW01icjtCU4oCkjTBP4xbtYJFABzSb6gH08Y1Lh51m TKXYLF7yKIQeNCuCBUaIlhofCvvLD0DyiizpNnp/jQTvxVM28+kKieB+cuDiCrjZucez UXgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="hYbGN5/p"; 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 jg16si4764105ejc.752.2021.10.20.07.04.44; Wed, 20 Oct 2021 07:04:45 -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="hYbGN5/p"; 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 4587868A62B; Wed, 20 Oct 2021 17:04:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C889689C64 for ; Wed, 20 Oct 2021 17:04:07 +0300 (EEST) Received: by mail-wm1-f41.google.com with SMTP id g79-20020a1c2052000000b00323023159e1so2026118wmg.2 for ; Wed, 20 Oct 2021 07:04:07 -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=d5nc4Xh1SKh5L4xwXHiIDBtTuu8VDwR4o7dOak6yAkg=; b=hYbGN5/phPdpWt1hAJp2nuygGeYA2i6etj5DJ0XvUARyJ1nSP7OjiiAypAqRTEfsdg 2x502chkpHrEIn+Ke/quNcNktbkvAf/WdF/vskZMUPsjk4YaiRZgzT6iHQZC6RpWXv+s kSAfG1bnCw+Dz2gm6VMx56srkYgdoTXEJOoujcjaA0Bx18IdRhIOPZuN3oBX1zWzA7KK W44EuBtMc+NL4uxIMY85lDnLFzb5i0FslNjnY01DzAmcyuSoWNTtpmYa/Vro3BzxJolZ VuilkGytm77r6f7BC52nfAcXkXvTwStTQbE1apzvuKheRKdOxp/3dB3HAV+M5yswmbiv /yEA== 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=d5nc4Xh1SKh5L4xwXHiIDBtTuu8VDwR4o7dOak6yAkg=; b=2EG2jaFgYAL2N/ylfodSCklskDgp/kuSqtMQHwKM4aVA5+MzJc4gEzaKbvSpNxef/7 4+M6h1sjjigwzKquZSnEoEJINTQiU+3S115ObsRlDQlZG45aD2FY9Pca1gdffCVzWkvw jqdzfXre1p1xLCecZh184jplkZWNbO1PFYtA5bEFVrjUjc79+uh5Psc2a4mCu/gH04RD r1d63cvJoZHHHYKjnDW+r5fSq/sNvFuypX2dVrh3e+NX1jDzaikJpaWpzC88aFCU5UvV FoDbVyuyPOKm8hae8Ehg+/Cp21OxSNWUE/KLNIKs2mH46bnxaifRhofZLHVmG2f7ddAa lZOw== X-Gm-Message-State: AOAM530u8M2EgwZkDezdX5gIjRReOuJIphUQpOyOKvsRWYYDT4QCA9wI WV4DsELosPTLR99J0+pLHPwzvYE4itc= X-Received: by 2002:a7b:c76b:: with SMTP id x11mr92556wmk.83.1634738646429; Wed, 20 Oct 2021 07:04:06 -0700 (PDT) Received: from localhost.localdomain ([82.129.92.120]) by smtp.gmail.com with ESMTPSA id l40sm2222743wms.31.2021.10.20.07.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 07:04:06 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Wed, 20 Oct 2021 15:03:54 +0100 Message-Id: <20211020140354.1124965-3-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 2/2 v2] avformat/mov: Do not hard fail if bit rate calculation overflows unless in explode mode 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: xS3ewQ0upytz bit_rate is not a critical field, and we shouln't hard fail if we can't caluclate it due to a large timebase - it needlessly breaks valid files. Signed-off-by: Derek Buitenhuis --- libavformat/mov.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 431f430368..0f948fface 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7992,10 +7992,11 @@ static int mov_read_header(AVFormatContext *s) /* Akin to sc->data_size * 8 * sc->time_scale / st->duration but accounting for overflows. */ st->codecpar->bit_rate = av_rescale(sc->data_size, 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", + av_log(s, AV_LOG_WARNING, "Overflow during bit rate calculation %"PRId64" * 8 * %d\n", sc->data_size, sc->time_scale); st->codecpar->bit_rate = 0; - return AVERROR_INVALIDDATA; + if (s->error_recognition & AV_EF_EXPLODE) + return AVERROR_INVALIDDATA; } } } @@ -8009,10 +8010,11 @@ static int mov_read_header(AVFormatContext *s) /* 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, 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", + av_log(s, AV_LOG_WARNING, "Overflow during bit rate calculation %"PRId64" * 8 * %d\n", sc->data_size, sc->time_scale); st->codecpar->bit_rate = 0; - return AVERROR_INVALIDDATA; + if (s->error_recognition & AV_EF_EXPLODE) + return AVERROR_INVALIDDATA; } } }