From patchwork Wed Sep 9 18:13:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22240 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AD47444B81C for ; Wed, 9 Sep 2020 21:13:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8472D68B954; Wed, 9 Sep 2020 21:13:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0FA816804BA for ; Wed, 9 Sep 2020 21:13:18 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id s12so3945055wrw.11 for ; Wed, 09 Sep 2020 11:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zMpbqsnzZiHuSU1ZoGP47eDT8OnTuSUAkmkSR/SBugc=; b=JMvvcS4Sw57avZcrb/yBUBOPlwfA6avETsoSdNYKEqOiohkyJ6/OTuVKujceWCcAYK x2z4GcW6PtTpTk9XQbn3gQ9EMOHfpZMb4oHMrbiqvhTS8lMfAN+uxKj3RQOO+JbMl1BH 6Rkd22WiQ27QSfW+yK/rA1DMaCMuubVXcmfxgM6QiLcyTQ8xS8m43LFisF/EGDZQ15/z Xyer3YX/iuNi80Bc0Vfkdq0vvArYi2z/13x0SGl9QYjbnfca1B3zjh3O7gAGp/axMHVC BnXY2CVQH/a2OfgpFNVMSQDhpmd+Yde8K/zfrR0EEODA2wjjjGddwScel4HJih7hoUub eHng== 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:mime-version:content-transfer-encoding; bh=zMpbqsnzZiHuSU1ZoGP47eDT8OnTuSUAkmkSR/SBugc=; b=O311AGzM3q0zj/TxZ7kqdYiTj8KpR+7xNVqQWiv5OiTeEz65ROhcpEKNSjrqK8If9Z jRg8gX5Z43Jj4X8eosgCTeBhIvq6KEML/s3k4wTs3TUqKofK4Mml9xB61xlOP1t9Q8bU mApfPoBo6KUIZWs7Fal5ewPHSZ6Pl7QWRzutXSMciJ5SCZE5ZAj5Eteq1IjI5p9NRYIJ 23h/0eVye2As0As2wm/WOVy80vGpLlnzHPTdq6exSn4qCOgSB88lyqiIa/5l0xexg7r+ ZRiG7iVuUvkL8qXHKotfG8sQ9Uc52yoCIWqc05EQiX9WvQdjmy0C2fqHeNW5ZoGWXBse QGBg== X-Gm-Message-State: AOAM531qvJg3XNxhFMzMRPunyZlnrnwgfRPbhFJmCbe5e4Pvmj/JFv4/ qlWO7O8L2+KeIoFEsR5SimyojStx/5o= X-Google-Smtp-Source: ABdhPJyxkZOJuwCvQPjCNh9rGdlanVCpWt5CvK6jYXLp9+qwyptGxsHjfZHtV4QA22517SCDvM0BAA== X-Received: by 2002:a5d:4151:: with SMTP id c17mr5496851wrq.302.1599675197222; Wed, 09 Sep 2020 11:13:17 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id a83sm4989911wmh.48.2020.09.09.11.13.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 11:13:16 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 9 Sep 2020 20:13:07 +0200 Message-Id: <20200909181307.8006-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200907024952.11697-3-andreas.rheinhardt@gmail.com> References: <20200907024952.11697-3-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/10] avformat/segment: Fix segfault on allocation error, avoid allocation 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If the user has set none of the options specifying the segments' durations, a default value of 2s is used by duplicating a "2" string and using av_parse_time() on it. Yet duplicating the string was unchecked and if the allocation failed, one would get a segfault in av_parse_time(). This commit solves this by instead turning said option to use AV_OPT_TYPE_DURATION (which also uses av_parse_time() internally), avoiding duplicating the string altogether. Signed-off-by: Andreas Rheinhardt --- Updated to use the AV_OPT_TYPE_DURATION as has been discussed with Ridley Combs on IRC; the whole patchset (with the exception of a nit in the last patch) has been lgtm'ed and so I will push it in a few hours unless there are further objections. libavformat/segment.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/libavformat/segment.c b/libavformat/segment.c index 0c96c8c50c..e84dc7a426 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -90,7 +90,6 @@ typedef struct SegmentContext { char *entry_prefix; ///< prefix to add to list entry filenames int list_type; ///< set the list type AVIOContext *list_pb; ///< list file put-byte context - char *time_str; ///< segment duration specification string int64_t time; ///< segment duration int use_strftime; ///< flag to expand filename with strftime int increment_tc; ///< flag to increment timecode if found @@ -689,7 +688,7 @@ static int seg_init(AVFormatContext *s) "you can use output_ts_offset instead of it\n"); } - if (!!seg->time_str + !!seg->times_str + !!seg->frames_str > 1) { + if ((seg->time != 2000000) + !!seg->times_str + !!seg->frames_str > 1) { av_log(s, AV_LOG_ERROR, "segment_time, segment_times, and segment_frames options " "are mutually exclusive, select just one of them\n"); @@ -703,15 +702,6 @@ static int seg_init(AVFormatContext *s) if ((ret = parse_frames(s, &seg->frames, &seg->nb_frames, seg->frames_str)) < 0) return ret; } else { - /* set default value if not specified */ - if (!seg->time_str) - seg->time_str = av_strdup("2"); - if ((ret = av_parse_time(&seg->time, seg->time_str, 1)) < 0) { - av_log(s, AV_LOG_ERROR, - "Invalid time duration specification '%s' for segment_time option\n", - seg->time_str); - return ret; - } if (seg->use_clocktime) { if (seg->time <= 0) { av_log(s, AV_LOG_ERROR, "Invalid negative segment_time with segment_atclocktime option set\n"); @@ -1051,7 +1041,7 @@ static const AVOption options[] = { { "segment_atclocktime", "set segment to be cut at clocktime", OFFSET(use_clocktime), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E}, { "segment_clocktime_offset", "set segment clocktime offset", OFFSET(clocktime_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, 86400000000LL, E}, { "segment_clocktime_wrap_duration", "set segment clocktime wrapping duration", OFFSET(clocktime_wrap_duration), AV_OPT_TYPE_DURATION, {.i64 = INT64_MAX}, 0, INT64_MAX, E}, - { "segment_time", "set segment duration", OFFSET(time_str),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E }, + { "segment_time", "set segment duration", OFFSET(time),AV_OPT_TYPE_DURATION, {.i64 = 2000000}, INT64_MIN, INT64_MAX, E }, { "segment_time_delta","set approximation value used for the segment times", OFFSET(time_delta), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, E }, { "segment_times", "set segment split time points", OFFSET(times_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E }, { "segment_frames", "set segment split frame numbers", OFFSET(frames_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E },