From patchwork Thu Apr 27 22:08:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Cooper X-Patchwork-Id: 3505 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp1050435vsd; Thu, 27 Apr 2017 15:08:46 -0700 (PDT) X-Received: by 10.28.19.6 with SMTP id 6mr3660963wmt.96.1493330925961; Thu, 27 Apr 2017 15:08:45 -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 q8si4683604wmd.71.2017.04.27.15.08.45; Thu, 27 Apr 2017 15:08: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=@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 C4299689748; Fri, 28 Apr 2017 01:08:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f178.google.com (mail-pf0-f178.google.com [209.85.192.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C1E56883EB for ; Fri, 28 Apr 2017 01:08:33 +0300 (EEST) Received: by mail-pf0-f178.google.com with SMTP id e64so1724441pfd.1 for ; Thu, 27 Apr 2017 15:08:35 -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=8wrYtD0EIcOpOzd9q233VGoNZ5o0lNKYnRHYCyOr/8o=; b=GgowAWIdFOq5z7IxmKg4uuw5OfA8XFdWBph/BoQr4MwlEm0121C5hFHKy1K3Z8gGwJ R6AHHAKh73RLxTEFE36T7FekGK8ErGaBR640FZ0vm65YyYCeFsFkzGVHBOrw/d86Oz3b /47tiinz1aXmpp4Ee5Q4W6jAD4bbuJi9XNoa1nrFpdjdOmHI4uJjy6XehRbrMS9XI30a JvvEo59iqxhUntwW1j0aN919aqd9Fa1miI9JyzMfLr1mrbsKOMBUipVE3eKOOyx1bOi7 3USk/Kai/SCNCbJ+JnFru57iRBymByHnwTCIh1STciVG1TXw+SAxgyDozXvBOBU/HF2B 70fA== 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=8wrYtD0EIcOpOzd9q233VGoNZ5o0lNKYnRHYCyOr/8o=; b=Uua9kCPJ/hTYNsEJghpjZ//ZLyigGr9+8+db0X7bRiIsO887Q+EUGS0Bg1qkQ7A4qq fY1S7tCEq25s52XFqACbR+owg1ZkpNrMe4Bzckc/fM/FbpL+nfWnCKAQ7yQLRGVHG6eB VkVxFzu+TCOAFrMKnPWEt2mNTFHwveZfhOIm4lTebKAWJq12TQc6zNsFGDPECmkdwS+P gxjhafCYX9qv6G8SHjcpyqzkO9b6sYQr497Y/6sm9NvmxcdwecUTFa/6Zsm3gA+gJvrt 5MGQ4zYSkn4yUEroRqipKvLcyDyVJcjX2bit6D6MGxefl8R/srcaUecvlN9S/QrMhclr O6Rg== X-Gm-Message-State: AN3rC/4kAI7/P8di8f8RgAMP4Zv7D/yfFNIJhHjXl/ja6dnh9T0R7XRb 0m4la7S48m8igGaW X-Received: by 10.84.236.7 with SMTP id q7mr10243363plk.176.1493330913648; Thu, 27 Apr 2017 15:08:33 -0700 (PDT) Received: from pinkiepie.mtv.corp.google.com ([172.27.196.67]) by smtp.gmail.com with ESMTPSA id r131sm5825843pgr.67.2017.04.27.15.08.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Apr 2017 15:08:32 -0700 (PDT) From: Lucas Cooper To: ffmpeg-devel@ffmpeg.org Date: Thu, 27 Apr 2017 15:08:29 -0700 Message-Id: <20170427220829.30519-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..d20d272f89 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");