From patchwork Thu Apr 27 16:52:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Cooper X-Patchwork-Id: 3503 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp929560vsd; Thu, 27 Apr 2017 09:52:43 -0700 (PDT) X-Received: by 10.223.130.168 with SMTP id 37mr4599029wrc.16.1493311963637; Thu, 27 Apr 2017 09:52:43 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l66si864343wrc.285.2017.04.27.09.52.42; Thu, 27 Apr 2017 09:52:43 -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=@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 71AA568838C; Thu, 27 Apr 2017 19:52:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f176.google.com (mail-pf0-f176.google.com [209.85.192.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BD332680474 for ; Thu, 27 Apr 2017 19:52:30 +0300 (EEST) Received: by mail-pf0-f176.google.com with SMTP id 194so32215170pfv.3 for ; Thu, 27 Apr 2017 09:52:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iY7A7rkp4CFs8sBr0uBhUSmSsXA8R9BRALJKeP1NY5I=; b=d0BTONEzo2q/j+SZfsEIngE+RZjR71ckTV4yIK1xHccTQSe6Hv15mQYSXrG0p3DooH feX1KVARA1ydla0FuwN5WzWmtPXY3GaSt0BUksBlYBBlVaPbYQPfJm2z+BQ7qbrv/Tlm P+llV8oDF8KFKskon9y+gHA0wyjB0uytyfVTb1DL1Pu/2lpaESih31Bv7klLHZjyGo68 cwLMLAtxXeiGQzLebetAPzocX6tBp/YJo524l5pxtspPns/NrGRodx6gaJ90Q4epIOd9 l/g+kwk/0M6onaw5kbymL1mjPst+RDltX7DSPaHpN/uTGggHBHLwe3boOd1tpDrquALk u/Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iY7A7rkp4CFs8sBr0uBhUSmSsXA8R9BRALJKeP1NY5I=; b=RCY+oiirkK+Jx2K0HQZOwzf/+CFCj2FvmbJoPJpll7EezDla/JXpp+ipA/iiUy1gNb BeV+ojsMInwLU3qPIuPRaNky5L0/6QaPOhnTj6m5LE+ayelLT6lD459uTD3sY5U50pVa kk2XSODZmVxJBZOS4tsq77FoM8GVK/mY9zEyDHv7enZ7BTCEYHHvD3WllPGpyYXaia5m cGkZp4CYSMzrSd1MjH/EFcRG4MrgDFXEHb5U3rgn3wTdHFHMyS1i4Bd0Mg7sGijtsEo2 29ynccL2bhLaaPe4zpzOJf7rFMY+VdhJuk8Ph4FwngcmdVnvVx4dDKW9A5Bt61+7Upjw +19A== X-Gm-Message-State: AN3rC/4Aj8czBdN7p5Ss3yzqMmV8l17lrREUnRF2B9u/ohisXgKaAosN KYV0CegPLxtYrj7R X-Received: by 10.99.7.203 with SMTP id 194mr7189444pgh.226.1493311950894; Thu, 27 Apr 2017 09:52:30 -0700 (PDT) Received: from pinkiepie.mtv.corp.google.com ([172.27.196.67]) by smtp.gmail.com with ESMTPSA id a77sm6369507pfe.33.2017.04.27.09.52.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Apr 2017 09:52:30 -0700 (PDT) From: Lucas Cooper To: ffmpeg-devel@ffmpeg.org Date: Thu, 27 Apr 2017 09:52:16 -0700 Message-Id: <20170427165216.12410-1-bobobo@google.com> X-Mailer: git-send-email 2.13.0.rc0.306.g87b477812d-goog In-Reply-To: <20170427140739.GT4714@nb4> References: <20170427140739.GT4714@nb4> Subject: [FFmpeg-devel] [PATCH] avformat/movenc: Explicitly address potential division by zero. 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 Cc: Lucas Cooper MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" find_fps attempts to infer framerate from AVCodec's timebase. When this results in a frame rate that isn't explicitly marked as supported in av_timecode_check_frame_rate, find_fps returns the AVStream's avg_frame_rate, which, per avformat.h, _may_ be set (or not). mov_get_mpeg2_xdcam_codec_tag, mov_get_h264_codec_tag and find_compressor attempt to call av_q2d on the return value of find_fps, which in the above case, may result in division by zero and therefore, an undefined frame rate when NaN is converted to int. --- libavformat/movenc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index e6e2313c53..a5c6ab88f1 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1321,12 +1321,21 @@ static AVRational find_fps(AVFormatContext *s, AVStream *st) return rate; } +static int defined_frame_rate(AVFormatContext *s, AVStream *st) +{ + AVRational rational_framerate = find_fps(s, st); + int rate = 0; + if (rational_framerate.den != 0) + rate = av_q2d(rational_framerate); + return rate; +} + static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track) { int tag = track->par->codec_tag; int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; AVStream *st = track->st; - int rate = av_q2d(find_fps(s, st)); + int rate = defined_frame_rate(s, st); if (!tag) tag = MKTAG('m', '2', 'v', '1'); //fallback tag @@ -1388,7 +1397,7 @@ static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track) int tag = track->par->codec_tag; int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; AVStream *st = track->st; - int rate = av_q2d(find_fps(s, st)); + int rate = defined_frame_rate(s, st); if (!tag) tag = MKTAG('a', 'v', 'c', 'i'); //fallback tag @@ -1850,7 +1859,7 @@ static void find_compressor(char * compressor_name, int len, MOVTrack *track) } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) { int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; AVStream *st = track->st; - int rate = av_q2d(find_fps(NULL, st)); + int rate = defined_frame_rate(NULL, st); av_strlcatf(compressor_name, len, "XDCAM"); if (track->par->format == AV_PIX_FMT_YUV422P) { av_strlcatf(compressor_name, len, " HD422");