From patchwork Sat Sep 19 16:35:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22483 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 0ACD944A6BC for ; Sat, 19 Sep 2020 19:36:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DD11668B666; Sat, 19 Sep 2020 19:36:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DBA6B68B51A for ; Sat, 19 Sep 2020 19:36:39 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id w5so8578954wrp.8 for ; Sat, 19 Sep 2020 09:36:39 -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:mime-version :content-transfer-encoding; bh=nElWszA6PXYFuf7WkEtMI/KgCNF1YycIR7FfxBVNMuE=; b=sAcm/aW46Qjy/8wpuktdebgHBmA27rA4MOIJgvpPROWwGzYRtyQ284Wb5WBl/omE9P p1OzUPP4RI+R93JGmaT/b8bJmIglj+AQugBrURxgVrWduolQgOyKSc/BBjzhw0er8Vl2 wwUfQ+XBhLtbI6/iQh6t3AOuiPwBzw1xrBhEbM0VMkZqF2YkjaRfgwxfXTxfEou51pkU wfVoNwxuT6JD0eY8560FhragCz8R1CsaaMxhZGks1paVEG8XXVj7gq/IcABSLE230bPn kpolkeAXeVDjKBJPPVv+1QHHlrjFzcf/AU2k3pQLTcAL+gFZk+k6WNH+RjsEtZAiq4qa ZFZg== 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:mime-version :content-transfer-encoding; bh=nElWszA6PXYFuf7WkEtMI/KgCNF1YycIR7FfxBVNMuE=; b=j1vSkhRPbNj5FUSocXqsb8DvlUbdmU55U6bfiCAZFVx21lkNnmnqv2wxl1o+LSikSs mCNzbD6yRkCH7BW7IUsa1b0AzUYXgidPMdDet9BvtVEfMQyjM3eX1VrGXcg7k85gjMQn JVvZUyTxy+nQe/JmjXbMbrS0FBU7AjRFnuixTRRiOa2FcEBMNsmIzVLb3H2jYgCG791g NUla2Q1hzJUdMPVU3d5UvFp3re9Yhq9uQFmqFJlTAi9qVLeQwWUkq4kMpJTqcLsJCOBD Z7ttRzi51UyW0nSalp1QjtTQeFxoZEAZfZ7tTq/8ImLXBXAagtRFAGNmXBKWp3HdAG4b NA6A== X-Gm-Message-State: AOAM532a+4VwRIhC0AviJGdu8G50896D+bZ1ZVnAEJETln5AvBL0rFPo 1oBcLIAbRRPpyNwpaW4c8EYDiG+0S0s= X-Google-Smtp-Source: ABdhPJzIe1nLAxatNIdBNUhlcYubQ1FbJBIqzkp5Z+WUbRzDwbMGeUJSkYWepwio2+qGEgALxtE4SQ== X-Received: by 2002:adf:f6c8:: with SMTP id y8mr46714148wrp.217.1600533399052; Sat, 19 Sep 2020 09:36:39 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:36:38 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:50 +0200 Message-Id: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/21] avformat/dashdec: Avoid double free on error 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" When using one of the AV_DICT_DONT_STRDUP_KEY/VAL flags, av_dict_set() already frees the key/value on error, so that freeing it again would lead to a double free. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 1e9985f32c..4048323c7d 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -1869,10 +1869,8 @@ static int save_avio_options(AVFormatContext *s) if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) { if (buf[0] != '\0') { ret = av_dict_set(&c->avio_opts, *opt, buf, AV_DICT_DONT_STRDUP_VAL); - if (ret < 0) { - av_freep(&buf); + if (ret < 0) return ret; - } } else { av_freep(&buf); } From patchwork Sat Sep 19 16:35:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22484 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 80F8644A83E for ; Sat, 19 Sep 2020 19:37:21 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 597CC68B6F7; Sat, 19 Sep 2020 19:37:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5FF7A68B6C0 for ; Sat, 19 Sep 2020 19:37:14 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id w2so8111039wmi.1 for ; Sat, 19 Sep 2020 09:37:14 -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=xEMKV8JXsMhq32Tw/FtGnsqIA8N3WUM9ZyqeseTpR24=; b=e8mrXX+qsCyInj/Y7MvFX+XSYEFF8FygVphKW7h4/viL1NC7DX/LStgcctcEk4Bf0l HtghXtQPjKf8A7p9K23KjBWeWhZxvAwJBRsreMhOMpOnmAaOqcBtzY4P6Lf7taiFwsvj ngcaIwWlAA4SdKSkQLpDkzD64Nhbc2pZ0iVfNXebARr4HZKemEWM5Nuqd//+jDAewGL/ dunBQH9ZmbM03UVfwoW6XZkBTsaNzR5TVKJEGES4zENlPwneCDZ88+w5UUUH/DpbTzrs RtAO6KOe5+gCnj3epY/c+ZbEvHY0589ZqGDLWxwc5pczZyN2WwIv5oCfDJsIS/Rt2jO5 fQtg== 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=xEMKV8JXsMhq32Tw/FtGnsqIA8N3WUM9ZyqeseTpR24=; b=Lu2SQRHIHUnxsaYt9NH8hwatDUDFkPW+NWKZrBdi7lnFl0TPfCbyL6g62tCEA+KVjm k1txwPMy9a9bCOII7C2EPlzwx7rUquXsIB986eZVTe6Z17P8rrN8ftGxCPUOL1kL1yM+ HMgc+pwsCQti0bOCPFb1SAbVFU3Y9F2T2YIW5SmUiwcr0NJwS0QB/ewnjR2wsgwqyr/9 KSgdPCYScE67zfs/6d/qAuOYpJPUNBPsxfhu7mgpfbC7m2cP2d24BZjB5PEjoakV6CbD sdavoedkLjDt7a2iLGdQwMWpPeffacYu//X4c39Qj6YuFX9WhAOy27J22vmH1sZ4AuA1 6BCA== X-Gm-Message-State: AOAM5326E/CVEqUvB/HlvOCyKvK83pw9klJvDTp45w2DF5p/uYedfrh2 B1KPagF2czXIzYS41NQG82Nid/DxSbk= X-Google-Smtp-Source: ABdhPJzJDlX4sZo5y4YF8BftnIIkkOZOfiuWc12a8b0FYU5k8p7gitGVuzyaSXsyoX0ws37iRCic3w== X-Received: by 2002:a1c:7714:: with SMTP id t20mr20996873wmi.186.1600533433430; Sat, 19 Sep 2020 09:37:13 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:12 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:51 +0200 Message-Id: <20200919163610.1099233-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/21] avformat/dashdec: Remove dead code 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" The code in question seems to have been copied from about 70 lines above; yet the code here is only executed if some of the variables (namely representation_segmenttemplate_node and fragment_template_node) are NULL, so it makes no sense to check them for a child element. Also remove a redundant resetting of a pointer to an AVFormatContext after avformat_close_input() (which already sets the pointer to NULL). Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 4048323c7d..f81b323d96 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -1047,12 +1047,7 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, fragmenturl_node = xmlNextElementSibling(fragmenturl_node); } - fragment_timeline_node = find_child_node_by_name(representation_segmenttemplate_node, "SegmentTimeline"); - - if (!fragment_timeline_node) - fragment_timeline_node = find_child_node_by_name(fragment_template_node, "SegmentTimeline"); - if (!fragment_timeline_node) - fragment_timeline_node = find_child_node_by_name(adaptionset_segmentlist_node, "SegmentTimeline"); + fragment_timeline_node = find_child_node_by_name(adaptionset_segmentlist_node, "SegmentTimeline"); if (!fragment_timeline_node) fragment_timeline_node = find_child_node_by_name(period_segmentlist_node, "SegmentTimeline"); if (fragment_timeline_node) { @@ -1898,7 +1893,6 @@ static void close_demux_for_component(struct representation *pls) memset(&pls->pb, 0x00, sizeof(AVIOContext)); pls->ctx->pb = NULL; avformat_close_input(&pls->ctx); - pls->ctx = NULL; } static int reopen_demux_for_component(AVFormatContext *s, struct representation *pls) From patchwork Sat Sep 19 16:35:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22485 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 A5F5844A83E for ; Sat, 19 Sep 2020 19:37:23 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92C6568B73E; Sat, 19 Sep 2020 19:37:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3921968B6F7 for ; Sat, 19 Sep 2020 19:37:15 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id s13so8098634wmh.4 for ; Sat, 19 Sep 2020 09:37:15 -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=a1zwyb6W1nUWUEqA+0xYfGzVyMKuo5JvmmMh9QOf6+k=; b=BmQOG752OMSD47bMg8z3N85M4PLPdvdxpDiCNzXs18NLgJlrVQWe1/9AxZLNk49sLN jyCAQXO18VKkso3kNbjcIRv0lWbmOK+rw8FlFp7Phf7N5cPv1yyaScFl2S4pkEUsyvyQ QGUdIKhAklpw8y139V7BvR3TYb/VWPjAB6KkRBvsxtqUWTeTMMNjjMBzDEr8d2H0Sd4c tbVYoyUdoAZ8HJZ/QjNSoGyjmYqOIG+dpEgqNUEG/pyGObisj2+MqbSkf+AtXJO6YfV9 y3KwDS91rKemQcpAhPIFrZeEXuZPR+LNzpn+e/8kR5GFZowqbStyKJY6x0ArLQ8dEFHD 8TWQ== 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=a1zwyb6W1nUWUEqA+0xYfGzVyMKuo5JvmmMh9QOf6+k=; b=eBIGpVoRuUpOjZ3uSi+1Oy1JA9HvRB9YIRtLxDoKiWcS3gVlyj7WHO09SlEPfoJIdc tEHAUUt21K8EIunt6H50h2pEU3it3r8FWiIttlcTwJPPklB4bonALYYypmkjrUKlz/66 e25KDRuFdcbkBiwHfTju0gtodBX/NKFwPbv6M01vAMElHligA4DMyKSVcJZIZxJcw93x Nhf6Jv87hfojSpDyLftnztaclObr/h4041ZJIYOoAT/uqUgP7RJHBoQlrlvBc9kSUogC 7+f5jWLFdPP3S9GtnvFvd4OwBwgqY/p9bPSm3AGfbFyViiNAaDtc8RAvCCHFo4KqI+yG Dseg== X-Gm-Message-State: AOAM533zh63P/L3tLFG0sXE5CT4TKrgOqHxN2+bjVvtjAHiZftTASqfY KNXh1CfmYMQpRgale0r1tHpAgolu/ok= X-Google-Smtp-Source: ABdhPJzO+qn9lL1Z2Dv4bQyN7X8N42Wxw4jJumukvNgJDSyGlxGqNQP43REoRL/GFK3v+6OTcIOVGw== X-Received: by 2002:a1c:f612:: with SMTP id w18mr20808092wmc.47.1600533434349; Sat, 19 Sep 2020 09:37:14 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:13 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:52 +0200 Message-Id: <20200919163610.1099233-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/21] avformat/dashdec: Don't leave representation in inconsistent state on error 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" This currently doesn't cause any trouble, because the only caller did not clean up the representation upon error at all; but fixing this is a prerequisite for doing so. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index f81b323d96..d84da16dbd 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -627,7 +627,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati initialization_val); if (!rep->init_section->url) { - av_free(rep->init_section); + av_freep(&rep->init_section); xmlFree(initialization_val); xmlFree(range_val); return AVERROR(ENOMEM); From patchwork Sat Sep 19 16:35:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22486 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 9F5E044A83E for ; Sat, 19 Sep 2020 19:37:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B8F768B768; Sat, 19 Sep 2020 19:37: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 7282E68B704 for ; Sat, 19 Sep 2020 19:37:16 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id x14so8565245wrl.12 for ; Sat, 19 Sep 2020 09:37:16 -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=vJF9n0Q3eXh+Xc3Dw3W3+rbVek4csrLvFXDh/XbPaNM=; b=gz+TW+o7MJbVJRnEIGG8jn48MlJlw1pMqDO57Y1bTxeqnEMw5+Gvaqy1tudAhy/XOa mYyzq/a7k8XWMSwhVI6BWBQ+EFjybyrrbuUdY7XXCaHwsLzjwc9W6o9yCyIMCvYJS3zH Y0BEgIgJom4ZT21t7WYeI/dLcNk7pxglGu4TEExD54olUEkuoy85jvt2UWiShrCkHr1E DKD3sgpz2FyA3E8PPakaVbI8N59CFyc7TgwuSzhrfREuGiOVoHRm1r6aOA7ASomVlSZG Bt6jNMVop0dMk9ulJTWUSSoN3vcL86RFFu19my85zz9kk6HpNqUe0qu61VBz21PdCobJ ID7Q== 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=vJF9n0Q3eXh+Xc3Dw3W3+rbVek4csrLvFXDh/XbPaNM=; b=ubr68kGOLJXebAZsEcqTISq6kiwRB87OBdpk+ekF9jGpmOtuvPm3htibCR5JfqgG97 LpirL/dsXemdDrkjixIkQcZ3FC2HwUQlM+VU5s6MMZusByviTLYwGcCAy87Ng0tCRhCh mlBlrwVHUdg4gdWnA6etEPpHSzRpkv1T7f6dy7H2fuOHVBGqUhLwGqkrB2R5ivAoq0Cd AL9H8ZJgY+EfKiQX1+XsbSlkkh57qaRB0vgpJOHZpk4iYX2PlgEfrd5W27lmcLZhsPA2 /1fGsUNCrWQsa4Nj6KAnKu64n5Egwpvx2uzOPWC3lLSv06talnhiPuqV9FaLts1Ly0c7 xGOw== X-Gm-Message-State: AOAM531bu7DjR+cX2LdzjqNwBmE6OWUQldjbJo5thnlAK7f+qp0EFdbu tmfe3NI10WUw4Leq4VdkG5Q1XQjBgQQ= X-Google-Smtp-Source: ABdhPJxCp9VK7QFF1oHHe524r4pPjb60/G+9N/uZJUmX+0uuGclZYot/lce13cSnqDnuzAzH77ZMXQ== X-Received: by 2002:adf:ec47:: with SMTP id w7mr46829851wrn.175.1600533435534; Sat, 19 Sep 2020 09:37:15 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:14 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:53 +0200 Message-Id: <20200919163610.1099233-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/21] avformat/dashdec: Don't overwrite and leak old initialization fragments 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" Signed-off-by: Andreas Rheinhardt --- One could also error out instead. libavformat/dashdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index d84da16dbd..3f51e079cf 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -614,6 +614,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati initialization_val = xmlGetProp(fragmenturl_node, "sourceURL"); range_val = xmlGetProp(fragmenturl_node, "range"); if (initialization_val || range_val) { + free_fragment(&rep->init_section); rep->init_section = get_Fragment(range_val); if (!rep->init_section) { xmlFree(initialization_val); From patchwork Sat Sep 19 16:35:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22487 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 0079B44A83E for ; Sat, 19 Sep 2020 19:37:26 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BB38A68B779; Sat, 19 Sep 2020 19:37:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5279D68B700 for ; Sat, 19 Sep 2020 19:37:17 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id o5so8568310wrn.13 for ; Sat, 19 Sep 2020 09:37:17 -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=LkOvbRAlZ0v43sB5guukvvHIJf6Mjn9i5fZXY8P6KhY=; b=o4pbXE3Uv/ejAD4PXTkkEdibuLWIACjVwfRZjWfIEc46xsulk8yJOUj55QrWSrr1H4 jj7/rwhWq1cNTUvGNK7Gkxt1NINzcE4EJhcM7BQDqt4iB4+r3hu93nca7V69ItGYGCNK vIk+R9X92P+PyYn81fTA5fvC8cw0hTBPADqetQbR51BAgUcJvWppmvBVCw/evrdJ/YUj HQkdmwa9a7dMtWUjT2EnkpDuI7hqfkT4lv+40gwSWKkTSO3zjutY4zv1eUlVm17S4Yap P128hQ/IKhd2QqfRqPL2g5l0r2oc0UHg8E2Qr7vy7vodUPu/O4ZB0usFKxEe7yTWziS7 T8JA== 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=LkOvbRAlZ0v43sB5guukvvHIJf6Mjn9i5fZXY8P6KhY=; b=N1EXYqvG0IP65+l20t/3G/B5j4pdfvQF4nx9cE5AWpTJ56kIWiWuHhveCF8d9eLo8b Y7A6/AoHarK+eHM3gXIVmVzDjFOTg+t03BFI5zgZ0ycIXPypNj0ZdSlAOw0ibn073ZRk iVaxgOhq6zQCxEC1ef25Z7Y77Y6PdeAjtEt6OSB6dsvnLfF0a/n/66qUn5fzvIfCLI2A 1azGKJAebESQVvjyppfsZzhpT2WLQyqfzqrRGn8qNPbSxSOpJHsegrvRu0rVg5IuSmEH kczUfnPIKe38zP8QFW/wQ1/S3XheydGwqjsBC8Bp9eU7zV2Jmof/JVX/spN73dVzD6wz QB+Q== X-Gm-Message-State: AOAM530Af0EiVQIg1QwVT5C3q/wXRP1tTMXlBJWOCMz2BpRYXS1B8I1+ AVwo9zzGSNyZsLgXthpwxxbiIYyJb70= X-Google-Smtp-Source: ABdhPJzgK0O7UcM2PLfbVqEiIt+OAQMpuD23RgZgh9F43R3qdEPyLw7pkbSGAJ1c7HeaLvAzEohE3g== X-Received: by 2002:adf:f3c6:: with SMTP id g6mr47548406wrp.340.1600533436502; Sat, 19 Sep 2020 09:37:16 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:15 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:54 +0200 Message-Id: <20200919163610.1099233-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/21] avformat/dashdec: Free strings as soon as they aren't needed anymore 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" Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 3f51e079cf..8b421a4493 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -616,9 +616,9 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati if (initialization_val || range_val) { free_fragment(&rep->init_section); rep->init_section = get_Fragment(range_val); + xmlFree(range_val); if (!rep->init_section) { xmlFree(initialization_val); - xmlFree(range_val); return AVERROR(ENOMEM); } rep->init_section->url = get_content_url(baseurl_nodes, 4, @@ -626,24 +626,20 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati rep_id_val, rep_bandwidth_val, initialization_val); - + xmlFree(initialization_val); if (!rep->init_section->url) { av_freep(&rep->init_section); - xmlFree(initialization_val); - xmlFree(range_val); return AVERROR(ENOMEM); } - xmlFree(initialization_val); - xmlFree(range_val); } } else if (!av_strcasecmp(fragmenturl_node->name, (const char *)"SegmentURL")) { media_val = xmlGetProp(fragmenturl_node, "media"); range_val = xmlGetProp(fragmenturl_node, "mediaRange"); if (media_val || range_val) { struct fragment *seg = get_Fragment(range_val); + xmlFree(range_val); if (!seg) { xmlFree(media_val); - xmlFree(range_val); return AVERROR(ENOMEM); } seg->url = get_content_url(baseurl_nodes, 4, @@ -651,15 +647,12 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati rep_id_val, rep_bandwidth_val, media_val); + xmlFree(media_val); if (!seg->url) { av_free(seg); - xmlFree(media_val); - xmlFree(range_val); return AVERROR(ENOMEM); } dynarray_add(&rep->fragments, &rep->n_fragments, seg); - xmlFree(media_val); - xmlFree(range_val); } } From patchwork Sat Sep 19 16:35:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22488 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 2CB6444A83E for ; Sat, 19 Sep 2020 19:37:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1079168B72C; Sat, 19 Sep 2020 19:37:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2BA7668B6EB for ; Sat, 19 Sep 2020 19:37:18 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id c18so8582132wrm.9 for ; Sat, 19 Sep 2020 09:37: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=TrcJ9XidjCSM+EycuWvKrChbEdUfoXxzWWABmYd9O04=; b=oucJZJRnhakACE6hlY5WPurWfk30/RW08PXyJlhGWWoP69Ox9xte0/lFFvRjmpp+3n XC1fU1SyUlsJ3VGJp4rcYBRck9CajJEnDWE+T+EG91V12X02NFvGju5FWEDdNb78wJM5 1TWY8OLinTekVRJYEDvPDfdvzelRQaIXtlubnOz4kFMZJKvGufjv+DIUFlEkZRsbQLpG xLRo2n6jibB1/XOX3pFiz1dDP4mM6l4h6tZwwgUuMReCiZSfipNzWeHDOuNLfnFV/fLN Sl3rpO5WFvUzdmoNYcVPRuYS050ZXff1LJ5zZxitQHZHLQsHLZ+tvKisGKa9K535io/H 2LaQ== 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=TrcJ9XidjCSM+EycuWvKrChbEdUfoXxzWWABmYd9O04=; b=gVhH71TKgxmMQjNkIL4tPGq23iAqdADP5uzUotKK6CbNMcHfY2HBDQyh5btkjotUbd fcBImjceb4RFa8dgVELuTnXISWJMRLdLNMQuuTzVJR1gBv7mkwTjOhwy5WChqYCFSzb2 cXCeE2DtsRR4t590pDoWAZjAs6PDJJow9oapK2xp6uXmzY2MnETtAAi7CRoEP6QdXMZv 0Y3DkB9yZ4ytyHNx79GyD6unTxOFbmB0ouxQnPjrTZHmXIIx/WvjtU+5sJPgcVFC2WwG YPb7fjkzTbnWAZtXQyr37pnRtq2wJkNQbaG8ScQM5o7HBklU7w6wy0OGns6Sq8A2aN6t wOGQ== X-Gm-Message-State: AOAM530QCHYUjgRiS4E2RjWgOWV8Ke2UG2p1gJ8Hq2HGDNta6CyB0B/i GML5mwoiE3nXY/TkMdw761SyK8CnG3k= X-Google-Smtp-Source: ABdhPJzBKLdivRIaJ4yEoDNQDciVBA8v4mxExsfIx7XHD7Gjy+tyjz/s6/7H0eM+5ChKyjqcGpTJOA== X-Received: by 2002:adf:cf01:: with SMTP id o1mr44545301wrj.421.1600533437485; Sat, 19 Sep 2020 09:37:17 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:16 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:55 +0200 Message-Id: <20200919163610.1099233-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/21] avformat/dashdec: Free subtitle representations on exit 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" Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 8b421a4493..3b83075e7a 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -2274,6 +2274,7 @@ static int dash_close(AVFormatContext *s) DASHContext *c = s->priv_data; free_audio_list(c); free_video_list(c); + free_subtitle_list(c); av_dict_free(&c->avio_opts); av_freep(&c->base_url); return 0; From patchwork Sat Sep 19 16:35:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22490 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 78E0144A83E for ; Sat, 19 Sep 2020 19:37:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6742A68B79C; Sat, 19 Sep 2020 19:37:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9065868B76C for ; Sat, 19 Sep 2020 19:37:19 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id w5so8580010wrp.8 for ; Sat, 19 Sep 2020 09:37:19 -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=fWRaVWNANWibIS3xzR0TcGFmLxwaHTNkJ+qKpHQkwaU=; b=nKn5Lj6DjO+JoQGmi3tEO5cs7WEGlUPt4KIwuegrM4dAB4SdlZ5kZXYlJunkWi5C9n 9ULQuATIMhBzyhNRsMcMRmjEw/vkVLFIodNM3aV0SkgC7myPirImsZYwNIuYjaE97UQt 9k2dikATMdOC2Jtfb49o2IQGOmhmycrnPfOjOZJIQ5Fnd3JIyQJmqnXZlqwbtbnh/IF+ 0X1zJ2iltcYn2fLJRQq+fv42y/KdiyeGeGmGiEGG6Igo1jHq7UkcSzBsGBKYcdccrkX0 xKQxgD3kh5w8PCvHxZ7zTkt5M2m8zjlnLbGCskRmeHJLGEM7oQEgPyEKNmH7RFy3je++ iiYw== 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=fWRaVWNANWibIS3xzR0TcGFmLxwaHTNkJ+qKpHQkwaU=; b=mncUv4bujhxMXBb6FroNHudT0HrDYXlashwroxITzuwqWesuSSIOX45gfrVeutN/vU f4H7Tv00xAiKKJZTYYPuqkKMbZDl00WlgAWp/WzvdZ2iln3yB45L+DLLnZWftGqe61Yj qczOcV8tGeioyeEHwAuZ5+njbz20wHyS1cr4RqUucNh0KkfX0yXEzDxCch98Ci1VSVrX UIJlQheCxT1BEQhsoGau4Kdys2o6gMUmVVh9B3lvpG/04/ssQcEaj3jynDhoLtXEADAI F1bRDy/gSNlnj19vEeJvu84JVWvlDjdhcq6od9O9aKaSZRjR5/qNe9hjLLIzKY8fLxIv s8fA== X-Gm-Message-State: AOAM531Gtd2oPNTwR3EeMSS3mmFJ6whXA2eHMvDtn1n1VPqNnGwzOREZ kOth9U5HbJYLWYJiy/ynDc3aBviSHtU= X-Google-Smtp-Source: ABdhPJyCAKYHJT/FbqHzkZKiqSEAwZIF79vV65RCRxmhRt8vWSgHWllsCj0Ta6oJ9XS3mSDnNnQpsQ== X-Received: by 2002:a5d:6343:: with SMTP id b3mr46494476wrw.179.1600533438819; Sat, 19 Sep 2020 09:37:18 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:18 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:56 +0200 Message-Id: <20200919163610.1099233-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/21] avformat/dashdec: Fix leak of AVDictionary on error 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" Just postpone the allocation of the dict until it is really needed (after the checks that can fail). Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 3b83075e7a..ee40f2aa0c 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -407,9 +407,6 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, const char *proto_name = NULL; int ret; - av_dict_copy(&tmp, opts, 0); - av_dict_copy(&tmp, opts2, 0); - if (av_strstart(url, "crypto", NULL)) { if (url[6] == '+' || url[6] == ':') proto_name = avio_find_protocol_name(url + 7); @@ -443,6 +440,8 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, return AVERROR_INVALIDDATA; av_freep(pb); + av_dict_copy(&tmp, opts, 0); + av_dict_copy(&tmp, opts2, 0); ret = avio_open2(pb, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp); if (ret >= 0) { // update cookies on http response with setcookies. From patchwork Sat Sep 19 16:35:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22492 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 21C2C44A83E for ; Sat, 19 Sep 2020 19:37:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0DCE268B7BF; Sat, 19 Sep 2020 19:37:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D359868B77C for ; Sat, 19 Sep 2020 19:37:20 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id e11so8747062wme.0 for ; Sat, 19 Sep 2020 09:37:20 -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=FUdLgtAKApwEGsH2EsH4k9nMSq1uaDCueU6huV0YlhM=; b=pQEYkKYk69ndKvYa/F0fd3Krqw32xF87Uc0MAf7ZTYBa7B41fi7MSe2aiAXHsXTNHK WYiphGRs1zSG5YmF/i4uXz8ZPdAe9s52wFgecA0QXbKd5LoA2ARs/Q9uYpad40bm64ss u1P+G1oGiE86R4s3kwI5RhgG6yNGwcZ43eBs74h/ObrSwEZmByIkoiGr4pqGfmUVTxG9 N9c0btIh8xoAp4uNUhPrfgMJaH5KrZeJd8FVCfc/P+Fu2yrmvXUt/PxoAGy7mPuyCayc 3843zNzFzDE7qAx2EKbLiU5kAnmbhdlocmjVVr5lmCGYY6CBYTs0jOYTYAjWvWtUSWTJ Dppw== 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=FUdLgtAKApwEGsH2EsH4k9nMSq1uaDCueU6huV0YlhM=; b=ZDcP/QCRnd1+x1axqoQMVwiQMSzkGqZnB3QoSjEAScSCzlH8VSbD9bieSOQM2HuSZP eF7s7AcCOu4AQDTqpW8JjipXcsKgXG9W2X3OrCpCGA7VT5QtYkme+a8pSwuQeIO7RsOn lIe1LZzR9ZzgnQiljXIhCu5lwVatAZcp1Pdux7bLKd4zAOeeSdmM2XB40vzhO3WAyz6N jrdc0Qf+Ao9Gi1Z56+te8+X7zjL9/rJYkJnupRyUkld9NJe38qyDb3qinJd9PnlTw5Y5 sM19FcEoZ8C6qd09JFPQImUN1a2n6ODAnPoUziEDCzYv2M8eqNjBTnMRZlQ0yUirk/oW 7Y/A== X-Gm-Message-State: AOAM531C6mdsRntfMQ/pB2SF60NXnfNGmPgmhM8tJnMp4225HZeMt4+k L2BsBeH1KXvJZVB4osG2JeuS6n90gw4= X-Google-Smtp-Source: ABdhPJxLYyX4EJ+xMEYl3HUmTSwcslWG2LWMZm/4Lyw+QYIgD5ZmfBidm1HNe3yhrjQmHNHATgk4LA== X-Received: by 2002:a1c:c256:: with SMTP id s83mr21485210wmf.93.1600533439913; Sat, 19 Sep 2020 09:37:19 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:19 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:57 +0200 Message-Id: <20200919163610.1099233-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/21] avformat/dashdec, hls: Update correct pointer to AVDictionary 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" open_url() in the DASH as well in the hls demuxer share a common bug: They modify an AVDictionary (i.e. set a new entry) given to them as AVDictionary *, yet if this new entry leads to reallocation and relocation of the AVDictionary, the caller's pointer will become dangling, leading to use-after-frees. So pass an AVDictionary **. (With the current implementation of AVDictionary the above can only happen if the AVDictionary was empty initially (in which case the new AVDictionary leaks); furthermore if the I/O is ordinary (i.e. opened by avio_open2() or ffio_open_whitelist()), the dict is never empty (it contains an rw_timeout entry from save_avio_options()). So this issue could only happen if the caller sets a nondefault io_open callback, but no AVIOContext (the AVFMT_FLAG_CUSTOM_IO flag won't be set in this case). In case of the HLS demuxer, it was also necessary that setting the "seekable" entry failed. Yet one should simply not rely on internals of the AVDict API.) Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 8 ++++---- libavformat/hls.c | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index ee40f2aa0c..55212661be 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -400,7 +400,7 @@ static void free_subtitle_list(DASHContext *c) } static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, - AVDictionary *opts, AVDictionary *opts2, int *is_http) + AVDictionary **opts, AVDictionary *opts2, int *is_http) { DASHContext *c = s->priv_data; AVDictionary *tmp = NULL; @@ -440,7 +440,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, return AVERROR_INVALIDDATA; av_freep(pb); - av_dict_copy(&tmp, opts, 0); + av_dict_copy(&tmp, *opts, 0); av_dict_copy(&tmp, opts2, 0); ret = avio_open2(pb, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp); if (ret >= 0) { @@ -451,7 +451,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, av_opt_get(*pb, "cookies", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&new_cookies); if (new_cookies) { - av_dict_set(&opts, "cookies", new_cookies, AV_DICT_DONT_STRDUP_VAL); + av_dict_set(opts, "cookies", new_cookies, AV_DICT_DONT_STRDUP_VAL); } } @@ -1714,7 +1714,7 @@ static int open_input(DASHContext *c, struct representation *pls, struct fragmen ff_make_absolute_url(url, c->max_url_size, c->base_url, seg->url); av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset %"PRId64", playlist %d\n", url, seg->url_offset, pls->rep_idx); - ret = open_url(pls->parent, &pls->input, url, c->avio_opts, opts, NULL); + ret = open_url(pls->parent, &pls->input, url, &c->avio_opts, opts, NULL); cleanup: av_free(url); diff --git a/libavformat/hls.c b/libavformat/hls.c index 3ab07f1b3f..f33ff3f645 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -617,7 +617,7 @@ static int open_url_keepalive(AVFormatContext *s, AVIOContext **pb, } static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, - AVDictionary *opts, AVDictionary *opts2, int *is_http_out) + AVDictionary **opts, AVDictionary *opts2, int *is_http_out) { HLSContext *c = s->priv_data; AVDictionary *tmp = NULL; @@ -664,7 +664,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5)) return AVERROR_INVALIDDATA; - av_dict_copy(&tmp, opts, 0); + av_dict_copy(&tmp, *opts, 0); av_dict_copy(&tmp, opts2, 0); if (is_http && c->http_persistent && *pb) { @@ -690,7 +690,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, av_opt_get(*pb, "cookies", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&new_cookies); if (new_cookies) - av_dict_set(&opts, "cookies", new_cookies, AV_DICT_DONT_STRDUP_VAL); + av_dict_set(opts, "cookies", new_cookies, AV_DICT_DONT_STRDUP_VAL); } av_dict_free(&tmp); @@ -1231,12 +1231,12 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, seg->url, seg->url_offset, pls->index); if (seg->key_type == KEY_NONE) { - ret = open_url(pls->parent, in, seg->url, c->avio_opts, opts, &is_http); + ret = open_url(pls->parent, in, seg->url, &c->avio_opts, opts, &is_http); } else if (seg->key_type == KEY_AES_128) { char iv[33], key[33], url[MAX_URL_SIZE]; if (strcmp(seg->key, pls->key_url)) { AVIOContext *pb = NULL; - if (open_url(pls->parent, &pb, seg->key, c->avio_opts, opts, NULL) == 0) { + if (open_url(pls->parent, &pb, seg->key, &c->avio_opts, opts, NULL) == 0) { ret = avio_read(pb, pls->key, sizeof(pls->key)); if (ret != sizeof(pls->key)) { av_log(pls->parent, AV_LOG_ERROR, "Unable to read key file %s\n", @@ -1260,7 +1260,7 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, av_dict_set(&opts, "key", key, 0); av_dict_set(&opts, "iv", iv, 0); - ret = open_url(pls->parent, in, url, c->avio_opts, opts, &is_http); + ret = open_url(pls->parent, in, url, &c->avio_opts, opts, &is_http); if (ret < 0) { goto cleanup; } From patchwork Sat Sep 19 16:35:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22494 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 04AEE44A83E for ; Sat, 19 Sep 2020 19:37:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DFC8768B877; Sat, 19 Sep 2020 19:37:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DA55E68B716 for ; Sat, 19 Sep 2020 19:37:21 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id z9so8462329wmk.1 for ; Sat, 19 Sep 2020 09:37:21 -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=gKgdld8t02vCOtJdqO+FcgBM6sQ9sCgOuLsgMA0cEVM=; b=ZWZxd5JMjioj2wa4HczT2pUcCjnzH9l4zAhQCTWHemqBGGwZNqTsIhkOVgawFP0Chc 2Hl/Ewfo/RMbYFqqHaKzugKBNoJ3NEMZRvpz3VU+OXMA/Z8CVzxNdZ/qnJQA6RnO8HCg ax/4uBtfbRI6WIzCPQzZTlaiXNDoLtcasUHl8X57WpQ/+VNHrXQk7oBWGmbl3q5ud4pK 3ZVxIQWlVCpbEOOs7KopOo5goeXYxwdbuHbOfNDAFJ8ODRqhPOibLgyL+GZCqLtxkTJ4 oU0PkkohyPrXltvb3PIi/WGExQZ+HhWiDQuNtRF59VrEgiXuGbyYuaKjAY5XJG3HseWC QqNw== 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=gKgdld8t02vCOtJdqO+FcgBM6sQ9sCgOuLsgMA0cEVM=; b=thv/N8AM2xxMpeRcvXje339nZYxeE/ZGlcNMGEXbGcW+emsHxt7P+MdP5El7gBUH3s AdbfHSyz3OXo+kXrpjNdoiLn+x/WoCwiaVs1JfWIHAQGat3VpSpQ4s9uVAHUCTeAdMpx diqloBDyEjiFJHlktS/YLJtONry9teQkrKsVfDHw3m3qv19Im9pVPyi0v8Nr0GP3+Vh8 RiT78oXgmw4FIdotahxq0JlXsC22GJxrkxJzWCyAj7ulWUyXURLCCw+P386p8ynhBlhg sCToTPQUQbnqKHsuZPUsqYt08UYoLPwQTYFWsyDAaCskV8Mt3eHoR/UHMxSK9Do5mXp3 OR2A== X-Gm-Message-State: AOAM530vVz/xzDAam750eRr9WcXb+XMmlO/L77tKUa/0Xx0Evyr0gIxZ BBtONgjfa1//z77/Tt47IFZgVxN9KAk= X-Google-Smtp-Source: ABdhPJz33as6xPva5c8R5fA54ZSso67DgLVF7EtIEBKzfIq5Zwplti+6YtYetx0sxoA3KIKmzh6XZA== X-Received: by 2002:a7b:c453:: with SMTP id l19mr20474116wmi.163.1600533441094; Sat, 19 Sep 2020 09:37:21 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:20 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:58 +0200 Message-Id: <20200919163610.1099233-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/21] avformat/dashdec: Check allocation of AVProgram 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" Signed-off-by: Andreas Rheinhardt --- What do we need this program for anyway? What sense does it make to create a single program containing all streams? libavformat/dashdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 55212661be..4f87ef981b 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -2137,6 +2137,7 @@ static int dash_read_header(AVFormatContext *s) AVProgram *program; program = av_new_program(s, 0); if (!program) { + ret = AVERROR(ENOMEM); goto fail; } From patchwork Sat Sep 19 16:35:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22496 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 2215E44A83E for ; Sat, 19 Sep 2020 19:37:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0DEFC68B814; Sat, 19 Sep 2020 19:37:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C0C3E68B75D for ; Sat, 19 Sep 2020 19:37:22 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id a17so8572086wrn.6 for ; Sat, 19 Sep 2020 09:37:22 -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=ssF3cZ0a1CS5lS0UqC81ViBmIKfioVA0oMGTBYquOqU=; b=Jx0/9LlKJc7zvGb/1rTu7Al0YwqcOFNJpRaaoPKgHl8YzEoBsYgKVolb4zGfEGna5W SYTAqsUC+9d/xFzmAHyqtF82HiOxDGl66/KeId93rzyHapykT1JKghaLq2HHcFmLpRux nXTuKdqxOT/Qv2v/xe+S78qUkEUf5BkikrWsEqai/Mm1ZbGPv1b8rQppR3tdnaDC8fOz 6p+LJKUdVMX29FtjX9Sz5f6kSt3N0dEUk9WgIxqAsItrV9U6DpHlHgj9ULpE3sN/kAhL 2q2eKAc/qQTf1XzLSEElKfyQs8n312XiomkPi7zQ+AOp9YxVPlAQ8LrV2GGdjFhUGvBK 95nQ== 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=ssF3cZ0a1CS5lS0UqC81ViBmIKfioVA0oMGTBYquOqU=; b=ZS8KKeeDCJ95twGd+PlYg9xkl5NZOs2TNicfXv9UMA8W0jay+QwC/F7vPBLyBU2OLm uhLhYtmneWl0PscIcRb6SzWi/P7Qco4UoKmzA0FzCNiqJY9xSOU2upWl6mOMdjIZTKMo dZWH/SxB20FibshXxnZxpLpX3EKnRv7YTdwaNzBg3cJzaQRYjAfrvmQTBkSo5Kc5Gj28 E/hBmLzmfgEJkwfimkcWKJyNis2ekRpbzgDpFRjq0FdUprokrL7D1aD8/M6JXF1/M7uX X0H5pXv2JoEqrxyilWBMgBt5yfW2Mj12dxTDbBg/zLIJkZd3BgcvYPh+GCsAxAbWDFq+ lE2Q== X-Gm-Message-State: AOAM533VTt5UxE3gUoXLKEZDrat0WpjRNX2W7NVO2axVYroI3VDJa0Ff S7KSOBcoujlIrsQLQ33qOu5RxvOytBU= X-Google-Smtp-Source: ABdhPJwtO7hkuKqKHGC4BdhudaCbudOqwERkfsMYGickDN9ztuNvTdQYKjrDLO/ShYlLXPAYgOutMA== X-Received: by 2002:adf:dfc9:: with SMTP id q9mr19511436wrn.400.1600533442008; Sat, 19 Sep 2020 09:37:22 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:21 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:35:59 +0200 Message-Id: <20200919163610.1099233-10-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/21] avformat/dashdec: Fix memleaks upon read_header failure 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" Signed-off-by: Andreas Rheinhardt --- Making sure that it's safe to call this demuxer's read_close function upon read_header failure was of course the initial rationale behind this patchset. libavformat/dashdec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 4f87ef981b..311a19e425 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -2047,6 +2047,7 @@ static int copy_init_section(struct representation *rep_dest, struct representat return 0; } +static int dash_close(AVFormatContext *s); static int dash_read_header(AVFormatContext *s) { @@ -2178,6 +2179,7 @@ static int dash_read_header(AVFormatContext *s) return 0; fail: + dash_close(s); return ret; } From patchwork Sat Sep 19 16:36:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22489 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 50C8F44A83E for ; Sat, 19 Sep 2020 19:37:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 34B1568B7A4; Sat, 19 Sep 2020 19:37:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE8ED68B75A for ; Sat, 19 Sep 2020 19:37:23 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id e11so8747142wme.0 for ; Sat, 19 Sep 2020 09:37:23 -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=qhECHf3CJ+wpzkm7vYXQIe+0DFdgrYEFZdkbCUSsx5M=; b=u5oiBOMyCc9OrE72W4W5rwZrBvFu7B20jzzpYKwjlcCN2W7Z206zB2Z/ff1fL8y4fC Z2Jda/uGg1ByeLb9E4boELYD+Qsdb346Yi/TD57IwFAfv/dViVqrm78mWp2y2zrZ7TAk 3nb/4EKaBCvINZhW85dDoZeYaRcYa5nYapPFh+X3VBaHQ2oRSH3xTv6FQTCQg4GyHZeX BYnh8QndZ0FUNT75S8gLcMt9sm966+DFOJRiH4xcYEPrk65EJtiPKRFhPJEe3FNwn5oI UIyr3oY/o1HtX0slsG8+VvsS+zAY6uFCNgFkrS5hHHzKASYwd6HmkNR/F4OAp3/dywfN fphQ== 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=qhECHf3CJ+wpzkm7vYXQIe+0DFdgrYEFZdkbCUSsx5M=; b=ukomskdeA1nPBsux/rLJ8REQUYVxgxybov3j52Qv/zAj7HNyWa61ann5ikudYUJ2rt YQYlP56Ipvd99/kgzVkpoQT6Oq7dsC/p7+/wE8Dpq8OoqqTFei8ZI/FeVhXaPUj7yMZ7 rVVUwR8PTDf4d58yu2xBYiKujLumLLVU87vPEHyJyZGhkQw+vNQc7yks2Hl8NEZft0A5 3lnVxYVMLQcMGozF2qmvPLkPVDEd+F1IHxFW9hmYUpyDImDJcLoKyih9ksEIloLy6/xf h9f5y9GodV6rN1dEdcmKNhQ0oNc8MyikJWNI8Ek/4tSDa9SpCfdQ6EqhBs4moBcX3d7A CJpA== X-Gm-Message-State: AOAM531NXqitJ/MIp9b4m7FZVMan5kRdUcFJglk0wwDpz9A0hcv3zTeE 29jVyKMXHhKJImGTXb20BOiOSWwGofc= X-Google-Smtp-Source: ABdhPJy+wa3yETu62PpOuN+bgvd7H4rUCWP+mLt1Aaa8X6/jepxvo6pVuGSg45Iwz7atkmKXs0jV3g== X-Received: by 2002:a05:600c:2118:: with SMTP id u24mr21069693wml.59.1600533442977; Sat, 19 Sep 2020 09:37:22 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:22 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:00 +0200 Message-Id: <20200919163610.1099233-11-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/21] avformat/dashdec: Remove unused index of representation 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" It is always zero. Also remove other unused elements. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 311a19e425..82cb335de9 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -80,12 +80,8 @@ struct representation { AVIOContext *input; AVFormatContext *parent; AVFormatContext *ctx; - AVPacket pkt; - int rep_idx; - int rep_count; int stream_index; - enum AVMediaType type; char id[20]; char *lang; int bandwidth; @@ -827,9 +823,6 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, xmlNodePtr adaptionset_supplementalproperty_node) { int32_t ret = 0; - int32_t subtitle_rep_idx = 0; - int32_t audio_rep_idx = 0; - int32_t video_rep_idx = 0; DASHContext *c = s->priv_data; struct representation *rep = NULL; struct fragment *seg = NULL; @@ -1073,15 +1066,12 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, switch (type) { case AVMEDIA_TYPE_VIDEO: - rep->rep_idx = video_rep_idx; dynarray_add(&c->videos, &c->n_videos, rep); break; case AVMEDIA_TYPE_AUDIO: - rep->rep_idx = audio_rep_idx; dynarray_add(&c->audios, &c->n_audios, rep); break; case AVMEDIA_TYPE_SUBTITLE: - rep->rep_idx = subtitle_rep_idx; dynarray_add(&c->subtitles, &c->n_subtitles, rep); break; default: @@ -1091,10 +1081,6 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, } } - video_rep_idx += type == AVMEDIA_TYPE_VIDEO; - audio_rep_idx += type == AVMEDIA_TYPE_AUDIO; - subtitle_rep_idx += type == AVMEDIA_TYPE_SUBTITLE; - end: if (rep_id_val) xmlFree(rep_id_val); @@ -1638,10 +1624,10 @@ static struct fragment *get_current_fragment(struct representation *pls) refresh_manifest(pls->parent); } if (pls->cur_seq_no <= min_seq_no) { - av_log(pls->parent, AV_LOG_VERBOSE, "old fragment: cur[%"PRId64"] min[%"PRId64"] max[%"PRId64"], playlist %d\n", (int64_t)pls->cur_seq_no, min_seq_no, max_seq_no, (int)pls->rep_idx); + av_log(pls->parent, AV_LOG_VERBOSE, "old fragment: cur[%"PRId64"] min[%"PRId64"] max[%"PRId64"]\n", (int64_t)pls->cur_seq_no, min_seq_no, max_seq_no); pls->cur_seq_no = calc_cur_seg_no(pls->parent, pls); } else if (pls->cur_seq_no > max_seq_no) { - av_log(pls->parent, AV_LOG_VERBOSE, "new fragment: min[%"PRId64"] max[%"PRId64"], playlist %d\n", min_seq_no, max_seq_no, (int)pls->rep_idx); + av_log(pls->parent, AV_LOG_VERBOSE, "new fragment: min[%"PRId64"] max[%"PRId64"]\n", min_seq_no, max_seq_no); } seg = av_mallocz(sizeof(struct fragment)); if (!seg) { @@ -1712,8 +1698,8 @@ static int open_input(DASHContext *c, struct representation *pls, struct fragmen } ff_make_absolute_url(url, c->max_url_size, c->base_url, seg->url); - av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset %"PRId64", playlist %d\n", - url, seg->url_offset, pls->rep_idx); + av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset %"PRId64"\n", + url, seg->url_offset); ret = open_url(pls->parent, &pls->input, url, &c->avio_opts, opts, NULL); cleanup: @@ -1738,8 +1724,7 @@ static int update_init_section(struct representation *pls) ret = open_input(c, pls, pls->init_section); if (ret < 0) { av_log(pls->parent, AV_LOG_WARNING, - "Failed to open an initialization section in playlist %d\n", - pls->rep_idx); + "Failed to open an initialization section\n"); return ret; } @@ -1807,7 +1792,7 @@ restart: ret = AVERROR_EXIT; goto end; } - av_log(v->parent, AV_LOG_WARNING, "Failed to open fragment of playlist %d\n", v->rep_idx); + av_log(v->parent, AV_LOG_WARNING, "Failed to open fragment of playlist\n"); v->cur_seq_no++; goto restart; } @@ -1933,7 +1918,7 @@ static int reopen_demux_for_component(AVFormatContext *s, struct representation pls->ctx->interrupt_callback = s->interrupt_callback; ret = av_probe_input_buffer(&pls->pb, &in_fmt, "", NULL, 0, 0); if (ret < 0) { - av_log(s, AV_LOG_ERROR, "Error when loading first fragment, playlist %d\n", (int)pls->rep_idx); + av_log(s, AV_LOG_ERROR, "Error when loading first fragment of playlist\n"); avformat_free_context(pls->ctx); pls->ctx = NULL; goto fail; @@ -2289,8 +2274,8 @@ static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t see int j = 0; int64_t duration = 0; - av_log(pls->parent, AV_LOG_VERBOSE, "DASH seek pos[%"PRId64"ms], playlist %d%s\n", - seek_pos_msec, pls->rep_idx, dry_run ? " (dry)" : ""); + av_log(pls->parent, AV_LOG_VERBOSE, "DASH seek pos[%"PRId64"ms] %s\n", + seek_pos_msec, dry_run ? " (dry)" : ""); // single fragment mode if (pls->n_fragments == 1) { @@ -2308,8 +2293,8 @@ static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t see if (pls->n_timelines > 0 && pls->fragment_timescale > 0) { int64_t num = pls->first_seq_no; av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline start n_timelines[%d] " - "last_seq_no[%"PRId64"], playlist %d.\n", - (int)pls->n_timelines, (int64_t)pls->last_seq_no, (int)pls->rep_idx); + "last_seq_no[%"PRId64"].\n", + (int)pls->n_timelines, (int64_t)pls->last_seq_no); for (i = 0; i < pls->n_timelines; i++) { if (pls->timelines[i]->starttime > 0) { duration = pls->timelines[i]->starttime; @@ -2330,8 +2315,8 @@ static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t see set_seq_num: pls->cur_seq_no = num > pls->last_seq_no ? pls->last_seq_no : num; - av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline end cur_seq_no[%"PRId64"], playlist %d.\n", - (int64_t)pls->cur_seq_no, (int)pls->rep_idx); + av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline end cur_seq_no[%"PRId64"].\n", + (int64_t)pls->cur_seq_no); } else if (pls->fragment_duration > 0) { pls->cur_seq_no = pls->first_seq_no + ((seek_pos_msec * pls->fragment_timescale) / pls->fragment_duration) / 1000; } else { From patchwork Sat Sep 19 16:36:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22491 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 551E444A83E for ; Sat, 19 Sep 2020 19:37:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4601568B7B7; Sat, 19 Sep 2020 19:37:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0DA1368B771 for ; Sat, 19 Sep 2020 19:37:25 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id e11so8747157wme.0 for ; Sat, 19 Sep 2020 09:37:24 -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=vUb431ldsmT/gjHnZZ/P8J54Mu2mCxf6ZwmVALHE64g=; b=Q6CuOdnxhK8BLTl6Wq2BDN3onx1EsW9HmSqRH7LBbKt9e0gBgBMkl7UsGt2tXYKhkm g0Zk5QWJHqqzKF+HFcl5P30rNcUl2ANUFErrJn3qz7lPz7oTh8mH7mx7XKvrv6NMqIc2 HvZlctkeBegNop7nkYRyuiWpVzBBPNZFm1E2usJnYXI7holUPt18HWyeHvf4HhzCJOsi nr79nLs6cO3AnqB/EjzxUZcYusyU7tIhe9mDknImAvVw9ON5sjUI9262YNMsQ3YYqFnS ++tfZVo1NNqF0w6Sq0joBLuiXeZmjlErtQPE15OGVk1kBXdwnGX4Gkgrnhtgi1mfV48e /y9w== 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=vUb431ldsmT/gjHnZZ/P8J54Mu2mCxf6ZwmVALHE64g=; b=UjlWLeLZbfiIte+7VxH9B+X1tMKwyTI+hFfVy1zTP4h28ioFg7Kk+xwbpEyqHJMtxp Sf6g38kL7haWl9LxeHEy//RFjJawj2OTcFdDzrvkGrBANOQx+hGiOyAAFyeK7V4/WXXQ sajinGSY/WIqibpKy1TZPQ5R+9PJpv2fs0U6bFTjjL+8bvHOprikICbrW+CmCs1wgJhh l7iOcMOM6gKSwWArAn/heSYnYj1hrdycQ25Ofu6+hZ8HjfDw99Qn/60Xjf2v0AdgAM62 LsDCTQJo7Ce6WVN969AabeFqx8+So9DEXeIzlW0cMYA9+AncGYUp5bwSPBJkzfVSpdHj btWg== X-Gm-Message-State: AOAM5308zgBE4auYv4HmIxIMRm2/Ia9xVP3zq76VG8knPqCtG3iJCzFV Eixsf/IPHIefZGJReuh2oAlBJS4JjpY= X-Google-Smtp-Source: ABdhPJxbp+5Eo0+H68tz4BKLesyEIxTamNwT+GMKRXV99K0IAxve+udwP1P0Co8X6V3Z2jOGhXXV5w== X-Received: by 2002:a1c:7418:: with SMTP id p24mr21335668wmc.123.1600533444040; Sat, 19 Sep 2020 09:37:24 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:23 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:01 +0200 Message-Id: <20200919163610.1099233-12-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/21] avformat/dashdec: Fix leak of representation on error 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 parsing a representation fails, it is not added to the list of representations and is therefore not freed in dash_close(); it therefore leaked in most error paths in parse_manifest_representation() (some error paths had (incomplete) code for freeing). This commit fixes freeing the representation in this case. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 52 +++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 82cb335de9..90d0e89925 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -887,9 +887,8 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, c->max_url_size = aligned(c->max_url_size + (rep_id_val ? strlen(rep_id_val) : 0) + (rep_bandwidth_val ? strlen(rep_bandwidth_val) : 0)); - if (ret == AVERROR(ENOMEM) || ret == 0) { - goto end; - } + if (ret == AVERROR(ENOMEM) || ret == 0) + goto free; if (representation_segmenttemplate_node || fragment_template_node || period_segmenttemplate_node) { fragment_timeline_node = NULL; fragment_templates_tab[0] = representation_segmenttemplate_node; @@ -907,19 +906,12 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, if (initialization_val) { rep->init_section = av_mallocz(sizeof(struct fragment)); - if (!rep->init_section) { - av_free(rep); - ret = AVERROR(ENOMEM); - goto end; - } + if (!rep->init_section) + goto enomem; c->max_url_size = aligned(c->max_url_size + strlen(initialization_val)); rep->init_section->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, initialization_val); - if (!rep->init_section->url) { - av_free(rep->init_section); - av_free(rep); - ret = AVERROR(ENOMEM); - goto end; - } + if (!rep->init_section->url) + goto enomem; rep->init_section->size = -1; xmlFree(initialization_val); } @@ -974,23 +966,19 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node); while (fragment_timeline_node) { ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node); - if (ret < 0) { - return ret; - } + if (ret < 0) + goto free; fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node); } } } else if (representation_baseurl_node && !representation_segmentlist_node) { seg = av_mallocz(sizeof(struct fragment)); - if (!seg) { - ret = AVERROR(ENOMEM); - goto end; - } + if (!seg) + goto enomem; seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, NULL); if (!seg->url) { av_free(seg); - ret = AVERROR(ENOMEM); - goto end; + goto enomem; } seg->size = -1; dynarray_add(&rep->fragments, &rep->n_fragments, seg); @@ -1027,9 +1015,8 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, baseurl_nodes, rep_id_val, rep_bandwidth_val); - if (ret < 0) { - return ret; - } + if (ret < 0) + goto free; fragmenturl_node = xmlNextElementSibling(fragmenturl_node); } @@ -1040,16 +1027,14 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node); while (fragment_timeline_node) { ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node); - if (ret < 0) { - return ret; - } + if (ret < 0) + goto free; fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node); } } } else { - free_representation(rep); - rep = NULL; av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id[%s] \n", (const char *)rep_id_val); + goto free; } if (rep) { @@ -1090,6 +1075,11 @@ end: xmlFree(rep_framerate_val); return ret; +enomem: + ret = AVERROR(ENOMEM); +free: + free_representation(rep); + goto end; } static int parse_manifest_adaptationset_attr(AVFormatContext *s, xmlNodePtr adaptionset_node) From patchwork Sat Sep 19 16:36:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22493 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 09D3B44A83E for ; Sat, 19 Sep 2020 19:37:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E9A2A68B7E1; Sat, 19 Sep 2020 19:37:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8694A68B76F for ; Sat, 19 Sep 2020 19:37:26 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id w5so8580181wrp.8 for ; Sat, 19 Sep 2020 09:37:26 -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=YdFQ5NSbZW3048RElGO/hCLBanJYxNnAxL2odliYE48=; b=Jr9F1db5Ly55v+DlJ2uk6VX9jouBvDxDfy+bupg0u7ksfH2yosHYvLUz8MOuTbEX9r yJJ+SNPHugTIxirSk7LmDHtlJNtyronQIF9Yj21EKiJl0U4q1J/UHoLhRfDB4batYTsk JNZ6Js0R+5kayWcSnzYosZETStkpyluz3V1EgYJ2F6/Yr5TjzAZLgwEn8MbbwqjgPZW0 d7sKXV9FG9WT+zh/sHNEMf4+acs+CfUzYROEVzcIx4UHGvWMoB1aAnrWjQReho/eJDp8 rf4Jd81Co6aYqY9xKbEMEso3lTulGxRcpHysWo2Q8+Qj2t0aa2Gx0pu+1Ka0nxGcEm2E sb9Q== 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=YdFQ5NSbZW3048RElGO/hCLBanJYxNnAxL2odliYE48=; b=aWsJraBHHl2lGlTDUgVgbnu1DGuaZoEBgvU5uz/5VHOmXhThJkogYX5NAXiFQb8pvH OGr6ixtPDQdfAUCKkiMsz+gEzIf11GCRZ2IfAACNbAVLPIybw06l+6S6yi2DSqtdu+J+ 8+Lf5iinkRoRzbmXSD3u3ES3rADQYNZNLsYZW2ggRNBSw4nJTaecf5fv4mBKctRTCVv+ Jykb78Ynn7lFA6YFqzNd36kR7yESVgnvDcs7M13p7wnkJg2bXDaJKFvIN1+HjaM/n24F +WyVQWl9USmZOGNjVRvSqLE7REWZR7Yt+SRvuLOE3rawOoC51IBJqEN2OmwTNUXlxI2u cGww== X-Gm-Message-State: AOAM5308Msuno8T3APSeZFQkG8iNuQfrWOwl6cSeQAX66f4UiO8EtL87 zX0bFq6nPKvsKb/vuHs6hN/SS9NznM0= X-Google-Smtp-Source: ABdhPJzHaU+z7d9Px50Po50lsnklk323X21aDuKSgC3th6EAt5gViXIwNQPqVqMbzlwtJyhRgmsVjQ== X-Received: by 2002:a5d:4e0a:: with SMTP id p10mr20487771wrt.170.1600533445567; Sat, 19 Sep 2020 09:37:25 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:24 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:02 +0200 Message-Id: <20200919163610.1099233-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/21] avformat/dashdec: Fix leak of string on error when parsing representation 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" The DASH demuxer currently extracts several strings at once from an xml document before processing them one by one; these strings are allocated, stored in local variables and need to be freed by the demuxer itself. So if an error happens when processing one of them, all strings need to be freed before returning. This has simply not been done, leading to leaks. A simple fix would be to add the necessary code for freeing; yet there is a better solution: Avoid having several strings at the same time by extracting a string, processing it and immediately freeing it. That way one only has to free at most one string on error. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 90d0e89925..ca2c2b5fd2 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -897,46 +897,45 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, fragment_templates_tab[3] = period_segmenttemplate_node; fragment_templates_tab[4] = period_segmentlist_node; - presentation_timeoffset_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "presentationTimeOffset"); - duration_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "duration"); - startnumber_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "startNumber"); - timescale_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "timescale"); initialization_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "initialization"); - media_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "media"); - if (initialization_val) { rep->init_section = av_mallocz(sizeof(struct fragment)); - if (!rep->init_section) + if (!rep->init_section) { + xmlFree(initialization_val); goto enomem; + } c->max_url_size = aligned(c->max_url_size + strlen(initialization_val)); rep->init_section->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, initialization_val); + xmlFree(initialization_val); if (!rep->init_section->url) goto enomem; rep->init_section->size = -1; - xmlFree(initialization_val); } - + media_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "media"); if (media_val) { c->max_url_size = aligned(c->max_url_size + strlen(media_val)); rep->url_template = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, media_val); xmlFree(media_val); } - + presentation_timeoffset_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "presentationTimeOffset"); if (presentation_timeoffset_val) { rep->presentation_timeoffset = (int64_t) strtoll(presentation_timeoffset_val, NULL, 10); av_log(s, AV_LOG_TRACE, "rep->presentation_timeoffset = [%"PRId64"]\n", rep->presentation_timeoffset); xmlFree(presentation_timeoffset_val); } + duration_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "duration"); if (duration_val) { rep->fragment_duration = (int64_t) strtoll(duration_val, NULL, 10); av_log(s, AV_LOG_TRACE, "rep->fragment_duration = [%"PRId64"]\n", rep->fragment_duration); xmlFree(duration_val); } + timescale_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "timescale"); if (timescale_val) { rep->fragment_timescale = (int64_t) strtoll(timescale_val, NULL, 10); av_log(s, AV_LOG_TRACE, "rep->fragment_timescale = [%"PRId64"]\n", rep->fragment_timescale); xmlFree(timescale_val); } + startnumber_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "startNumber"); if (startnumber_val) { rep->start_number = rep->first_seq_no = (int64_t) strtoll(startnumber_val, NULL, 10); av_log(s, AV_LOG_TRACE, "rep->first_seq_no = [%"PRId64"]\n", rep->first_seq_no); From patchwork Sat Sep 19 16:36:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22495 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 036CD44A83E for ; Sat, 19 Sep 2020 19:37:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D9F9268B875; Sat, 19 Sep 2020 19:37:34 +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 984E868B72C for ; Sat, 19 Sep 2020 19:37:27 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id k15so8579592wrn.10 for ; Sat, 19 Sep 2020 09:37:27 -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=pwIqOJt03STTa3+VihclEZel3mrWwQnEdpQ3cd8eVW4=; b=tApGokeYG9SCjAwZ8yc3++ArJBMhTdaP9CSh/Q3A6+J5zizxK+EeCKmKHts9r7Oc/2 vCr4E90d2B1kVFqf3QCVBcvOsl63NEkZwTewTPO+cR70RJ7VOEDNm4DhSt31vAYnXIUr b5NJ3LNtx0rt4Ik54grDzLQqlmWI75HyiC5a3iZMTnrT+/Sb7XRA+FARiIGSIZrIoAlu 92bzuEr9tPvGALzTl5GxEsFOlbHcaGBahnftVFOfCEsdaFvjD3J1uuaMOw/drQ2Iw7QF YEg5hZ9nAQA76mL4OquYncC8+uWiOqmbDZtGuTvEBEMx9OA60yZdeh7t8aChN2rQR3Lj exyA== 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=pwIqOJt03STTa3+VihclEZel3mrWwQnEdpQ3cd8eVW4=; b=N+2ob1JPoPj/D4ONgegtjl2ioww8rCSHzRQO9zF++sPJCGYmrN2dy3tEjS6CGXIZpw g0FrUAONchqAyyWrUmGU3yuXDix6h7DrMKSgqvc0eZmTNpHv67MSM+GpuCdg+gRTi684 eTJs+Dd0kCG5y+yUTJZda2c2PvbrEk6dzNTqm+unIZ31mjqCY6etkmwzFgo187cqj5fS uWLErEoh0vo+HQaOr8eZBt5vKOPbn4apmsurQBQ19mW4sMlnyRe6GRg2+6sE/rEDMo2U cofBN/qsgq3pNiV7PL9q9sthfvq519UF/U99bl/+vZlOqXHfdnjMVgEXqPoPaG1h8Y2y SpsQ== X-Gm-Message-State: AOAM533PCN80POsmmar6EIv2AE6JKEV29a5F4XgKkWH4SLpUvKIszsl+ IyGZgr550MBN2C7gGtvdepjoIRb60Vg= X-Google-Smtp-Source: ABdhPJwouJzFzslFFvRzqlqlxhvtBAdxwRVBopuxo+48JGBjxz7+9EUHiWQQeKKvJlJLwjKtKa7YNA== X-Received: by 2002:adf:e54f:: with SMTP id z15mr41968300wrm.136.1600533446763; Sat, 19 Sep 2020 09:37:26 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:25 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:03 +0200 Message-Id: <20200919163610.1099233-14-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/21] avformat/dashdec: Fix leak of representation languages 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" These languages are normally freed after having been added as metadata to their respective AVStreams. Yet if one never reaches said point, they leak. This can happen as a result of an error when reading the header or as a result of refreshing the manifests. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index ca2c2b5fd2..4d4611ef04 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -359,6 +359,7 @@ static void free_representation(struct representation *pls) } av_freep(&pls->url_template); + av_freep(&pls->lang); av_freep(&pls); } From patchwork Sat Sep 19 16:36:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22497 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 1738C44A83E for ; Sat, 19 Sep 2020 19:37:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F167268B82C; Sat, 19 Sep 2020 19:37:36 +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 1DABF68B7A0 for ; Sat, 19 Sep 2020 19:37:29 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id c18so8582399wrm.9 for ; Sat, 19 Sep 2020 09:37:29 -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=ifRBpz+i9hyzoFUGpIi3gevLnrpiOXxbkrE5/JTgj/s=; b=Eolvs89tei6hYtqcKFwj59xP+hy4mIFkCWdgAqx4lMie5SKOSsiDwyE6Z5cDzW+IWc UVJOMN+4Mcti2QYBgYkW+wokjd6YNo4oKAPLAhuFMKlB+TYqL8cRv0e8uCmv66zvUnPc 2KQ6fUpjBkTfNOZyj1HLYVvdWuOPKEH4gz1xHSXQhOjPRIs1vNAhi2oVsVOsTqkQ+WcZ zag6gh/Usp54SR+63g+eZcf0RUXrHd2aBlByGBoTPE6XW6Cd+6s2RGcPPgnreMASkO3C baqdMvRo9iRa5YFkqVWYLwiAYA74vIxdUjswIoVpNIHb8F7WpI7Ny1UZdyrpGonW71pY c0RQ== 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=ifRBpz+i9hyzoFUGpIi3gevLnrpiOXxbkrE5/JTgj/s=; b=NPkgkl4gpYsCzJPq0AWO9TVD5GsGWAeSsZvNUr3eURhBi2lhUSA6iAE8+mf4GwwJxV eHHomTifpmKvaieWzBOsix0K80KRKWqToen3NMUiKzf3Rkj2ndEqLKbn+XSYmy+1Z3hN 3ieciEXxkkt/pThI7n0RDSpn7nbAqEUm7F4k3zf4YVgrxyiIJzQ7fCke4DuwCVezhYLD AQSdbpK7crs0bMYxluC84cexTkQjQxWoHrH981VjHOFNtpNIsYb1Ji0NNJeK6Rl6tKuE ks/NM7VSdWU16BoqBasLHqWubMKJzG1qH9QzLO5jkgVRCOIBIYZKQffU+/JAg8g/exY0 XznQ== X-Gm-Message-State: AOAM530jPIMbuxBOLvcQFxl+bS8QFm8qKEcCPs0JUKGE3Jo8Ie31S3YW H86c/xP6C3XeWgmbr1ecbN7C/dbsXdY= X-Google-Smtp-Source: ABdhPJwWluKSO7czxM0+o2Y0i8xBmLRzBqelxyaj4HsfYb2u/OTOhaLpw+767LbMQyKvOovIsPb7TQ== X-Received: by 2002:adf:eb86:: with SMTP id t6mr43562530wrn.411.1600533448050; Sat, 19 Sep 2020 09:37:28 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:27 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:04 +0200 Message-Id: <20200919163610.1099233-15-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/21] avformat/dashdec: Fix memleaks on error to add representation to dynarray 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" Up until now, the DASH demuxer used av_dynarray_add() to add audio/video/subtitles representations to arrays. Yet av_dynarray_add() frees the array upon failure, leading to leaks of its elements; furthermore, the element to be added leaks, too. This has been fixed by using av_dynarray_add_nofree() instead and by freeing the elements that could not be added to the list. Furthermore, errors from this are now checked and returned. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 4d4611ef04..e1554d077b 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -605,6 +605,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati char *media_val = NULL; char *range_val = NULL; int max_url_size = c ? c->max_url_size: MAX_URL_SIZE; + int err; if (!av_strcasecmp(fragmenturl_node->name, (const char *)"Initialization")) { initialization_val = xmlGetProp(fragmenturl_node, "sourceURL"); @@ -648,7 +649,11 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati av_free(seg); return AVERROR(ENOMEM); } - dynarray_add(&rep->fragments, &rep->n_fragments, seg); + err = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg); + if (err < 0) { + free_fragment(&seg); + return err; + } } } @@ -660,6 +665,7 @@ static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representat { xmlAttrPtr attr = NULL; char *val = NULL; + int err; if (!av_strcasecmp(fragment_timeline_node->name, (const char *)"S")) { struct timeline *tml = av_mallocz(sizeof(struct timeline)); @@ -685,7 +691,11 @@ static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representat attr = attr->next; xmlFree(val); } - dynarray_add(&rep->timelines, &rep->n_timelines, tml); + err = av_dynarray_add_nofree(&rep->timelines, &rep->n_timelines, tml); + if (err < 0) { + av_free(tml); + return err; + } } return 0; @@ -975,13 +985,15 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, seg = av_mallocz(sizeof(struct fragment)); if (!seg) goto enomem; - seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, NULL); - if (!seg->url) { + ret = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg); + if (ret < 0) { av_free(seg); - goto enomem; + goto free; } + seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, NULL); + if (!seg->url) + goto enomem; seg->size = -1; - dynarray_add(&rep->fragments, &rep->n_fragments, seg); } else if (representation_segmentlist_node) { // TODO: https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html // http://www-itec.uni-klu.ac.at/dash/ddash/mpdGenerator.php?fragmentlength=15&type=full @@ -1051,18 +1063,20 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, switch (type) { case AVMEDIA_TYPE_VIDEO: - dynarray_add(&c->videos, &c->n_videos, rep); + ret = av_dynarray_add_nofree(&c->videos, &c->n_videos, rep); break; case AVMEDIA_TYPE_AUDIO: - dynarray_add(&c->audios, &c->n_audios, rep); + ret = av_dynarray_add_nofree(&c->audios, &c->n_audios, rep); break; case AVMEDIA_TYPE_SUBTITLE: - dynarray_add(&c->subtitles, &c->n_subtitles, rep); + ret = av_dynarray_add_nofree(&c->subtitles, &c->n_subtitles, rep); break; default: av_log(s, AV_LOG_WARNING, "Unsupported the stream type %d\n", type); break; } + if (ret < 0) + goto free; } } From patchwork Sat Sep 19 16:36:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22498 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 03D374493ED for ; Sat, 19 Sep 2020 19:39:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1120768B90C; Sat, 19 Sep 2020 19:37:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 405DD68B846 for ; Sat, 19 Sep 2020 19:37:30 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id c18so8582425wrm.9 for ; Sat, 19 Sep 2020 09:37:30 -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=PVosB0XA8OroF3hBINJ13trGicM4jr+Fo4djKaF75hk=; b=Q6Knr8JuA0GcWQ3TKXkAF1e4UDSnO59rC0HsPSsX8qt7yfm5Ckhydm/i2xsz7Yab5V AxBoJrHuogIjtyP271XpNREhdsAj2C8CrPI3aQ+KYLGm0PigWFG1nzBSaEoN0RurywSk aD2S2NXOe7pNXZZ+ULjvPuSk73QXJukiPUINd+Q4SnTmoy9bse2QDGGtZp/45DWXLXE4 cPJ/I6KRxmHTPZ+Ob2HVKmVTYKHKwzi4YYz3aQIGcCwza5nLujh4gxP/2t7qzXdZgJ84 DE6nlIlxSQKQ/VoBRmaMPkBOcRiZ0N6S+J62TTkdrzl3BFkb5CGZ82Y2e539nr3biNV3 vbdQ== 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=PVosB0XA8OroF3hBINJ13trGicM4jr+Fo4djKaF75hk=; b=YC3scvh/mBEEdRdoZkH6fsVGsX62yAXfCFLtfKnOSwzBU346rnmv7qV1vuOgZG5HxI xvOjJhjsk7zR6HMtY6HXOzAgUWaJHWqSyn3vOuLOFVq39DeerB9zmua0MaucoF3XqcmE tsf3lDV6vU3lMAloGSzPfKZ8Nv6+Zs6r70b50CKZElBhBImP6C53++jM4+idTFnBm5d1 Lzf1q9dA493rPx8olq1ehGaGO9H15wpWB6llVIoalg+uKAcR/JtySKhZMb2xkmeQlrCF R1EbqIfKIimYF89Da4g5w+s/8M37fIdiZa8ItOM0E2Y6rdxh1Jh1u81aJTw6iyLT139u k7yw== X-Gm-Message-State: AOAM532Rz6xTNMethO/CprwDIdRe7sLhJfoJ5rcI29vsyj/p5D9Ttuee GEvpEK0S7D1ghyRJVGZrenubb9NJj/8= X-Google-Smtp-Source: ABdhPJw+w2NO+shrbaheURwPGIP3jZRaqPvtCn2ngQG5genMrLbtDhJNEBxWExU4O3zL0HPA5LTlaQ== X-Received: by 2002:a5d:46cf:: with SMTP id g15mr44227476wrs.107.1600533449148; Sat, 19 Sep 2020 09:37:29 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:28 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:05 +0200 Message-Id: <20200919163610.1099233-16-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/21] avformat/dashdec: Remove redundant checks 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" This commit removes two always-true checks as well as a dead default case of a switch. The check when parsing manifests is always true, because we now jump to the cleaning code in case the format of the representation is unknown. The default case of the switch is dead, because the type of the representation is already checked at the beginning of parse_manifest_representation(). The check when reading the header is dead, because we error out if an error happened before. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index e1554d077b..d75ff92a7b 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -1049,7 +1049,6 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, goto free; } - if (rep) { if (rep->fragment_duration > 0 && !rep->fragment_timescale) rep->fragment_timescale = 1; rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0; @@ -1071,13 +1070,9 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, case AVMEDIA_TYPE_SUBTITLE: ret = av_dynarray_add_nofree(&c->subtitles, &c->n_subtitles, rep); break; - default: - av_log(s, AV_LOG_WARNING, "Unsupported the stream type %d\n", type); - break; } if (ret < 0) goto free; - } } end: @@ -2042,6 +2037,7 @@ static int dash_read_header(AVFormatContext *s) { DASHContext *c = s->priv_data; struct representation *rep; + AVProgram *program; int ret = 0; int stream_index = 0; int i; @@ -2123,8 +2119,6 @@ static int dash_read_header(AVFormatContext *s) } /* Create a program */ - if (!ret) { - AVProgram *program; program = av_new_program(s, 0); if (!program) { ret = AVERROR(ENOMEM); @@ -2164,7 +2158,6 @@ static int dash_read_header(AVFormatContext *s) av_freep(&rep->lang); } } - } return 0; fail: From patchwork Sat Sep 19 16:36:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22499 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 389AE4493ED for ; Sat, 19 Sep 2020 19:39:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0A8EA68B920; Sat, 19 Sep 2020 19:37:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0A3D468B773 for ; Sat, 19 Sep 2020 19:37:30 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id q9so8115338wmj.2 for ; Sat, 19 Sep 2020 09:37:30 -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=OYZKNz9htLaj+VRbd7B8Tv+xOwWfuxQvvLSZ+AafMlY=; b=HccVWTBasFLoAeIY/Bw0+Etm/dM7A3z8siVQSszCU2x16BWIgFW/mVKopYxMwKPtjs L8LoKXJCVElX00CWKtvkEdDyW7rUZxdQ0NomMBItS6PaeTAbzU11TsIDZ03FT0/F8cOe mXH/zDBODuKOR994/cCO97lGjiWtIi/9iVCpTdRnDinKu+QTgLMRRerFFatr1qN4aMb1 1+52SMNIw8HUhSAXP9o1Lh75eBfQeFUVlQ5S4YGTl/yCnGzbYPZzJIdMT8o2WHdRtZSG b7uL+oZfSsWQnyqWAHqdy+vwjEcmpe+TnK3tVeS9kISX55wJgrA/C2VVhRR8eWBB4xDz REqg== 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=OYZKNz9htLaj+VRbd7B8Tv+xOwWfuxQvvLSZ+AafMlY=; b=A5abFJsrvj8LHHlxx5ymBC2AhI4+U0DLDJnMNRNdOeqA08MAMAazY3YePBPh6eru/P pcOscYW3wnEWfg4lRcnPBie1yOpIAmybvleCPByI/xvuFVuKNxtoI1N6gz2yzMT01ITZ SBTBKJx56X9tDVA+sj09nhqHd6313IKOpmYddmCdP9VkwdwYaIx6wkAk5Rv1LO/emQcL 0DfIZQd67vpIJf1Gg4pECJOlanWGfE84tAfpCjz9C3UQ6uZ2j99v0fcSiue9iqX+8OCb VdwleBWkredDrouOJkVlrXbWooMW6KiJ5xxyUV9nX/mHd7dCEU+SfNrfwXBqDIF3TCR2 fp2w== X-Gm-Message-State: AOAM532wfTWDNf9KqoDyZDjmR/Noa8vd+4xxM95XR5Hr81J0hBZ6IC3G Ss4GJChElOyZKcVnH5l2m/0hBb5383s= X-Google-Smtp-Source: ABdhPJzBb51MCcgQ8JB7tpxgq9bVtUZnuriPcvU8tueBrSiSFHsGK5ZLtbjref1WFFgZ12+Diq7nyQ== X-Received: by 2002:a1c:740c:: with SMTP id p12mr21272019wmc.176.1600533450199; Sat, 19 Sep 2020 09:37:30 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:06 +0200 Message-Id: <20200919163610.1099233-17-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/21] avformat/dashdec: Return early for unsupported representations 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" This allows to reduce the level of indentation for parsing the supported representations (audio, video and subtitles). It also allows to avoid some allocations and frees for unsupported representations. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index d75ff92a7b..3b6ae29b1b 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -852,9 +852,7 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, char *val = NULL; xmlNodePtr baseurl_nodes[4]; xmlNodePtr representation_node = node; - char *rep_id_val = xmlGetProp(representation_node, "id"); - char *rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth"); - char *rep_framerate_val = xmlGetProp(representation_node, "frameRate"); + char *rep_id_val, *rep_bandwidth_val; enum AVMediaType type = AVMEDIA_TYPE_UNKNOWN; // try get information from representation @@ -866,28 +864,29 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, // try get information from adaption set if (type == AVMEDIA_TYPE_UNKNOWN) type = get_content_type(adaptionset_node); - if (type == AVMEDIA_TYPE_UNKNOWN) { + if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO && + type != AVMEDIA_TYPE_SUBTITLE) { av_log(s, AV_LOG_VERBOSE, "Parsing '%s' - skipp not supported representation type\n", url); - } else if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) { + return 0; + } // convert selected representation to our internal struct rep = av_mallocz(sizeof(struct representation)); - if (!rep) { - ret = AVERROR(ENOMEM); - goto end; - } + if (!rep) + return AVERROR(ENOMEM); if (c->adaptionset_lang) { rep->lang = av_strdup(c->adaptionset_lang); if (!rep->lang) { av_log(s, AV_LOG_ERROR, "alloc language memory failure\n"); av_freep(&rep); - ret = AVERROR(ENOMEM); - goto end; + return AVERROR(ENOMEM); } } rep->parent = s; representation_segmenttemplate_node = find_child_node_by_name(representation_node, "SegmentTemplate"); representation_baseurl_node = find_child_node_by_name(representation_node, "BaseURL"); representation_segmentlist_node = find_child_node_by_name(representation_node, "SegmentList"); + rep_id_val = xmlGetProp(representation_node, "id"); + rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth"); baseurl_nodes[0] = mpd_baseurl_node; baseurl_nodes[1] = period_baseurl_node; @@ -1054,10 +1053,14 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0; strncpy(rep->id, rep_id_val ? rep_id_val : "", sizeof(rep->id)); rep->framerate = av_make_q(0, 0); - if (type == AVMEDIA_TYPE_VIDEO && rep_framerate_val) { + if (type == AVMEDIA_TYPE_VIDEO) { + char *rep_framerate_val = xmlGetProp(representation_node, "frameRate"); + if (rep_framerate_val) { ret = av_parse_video_rate(&rep->framerate, rep_framerate_val); if (ret < 0) av_log(s, AV_LOG_VERBOSE, "Ignoring invalid frame rate '%s'\n", rep_framerate_val); + xmlFree(rep_framerate_val); + } } switch (type) { @@ -1073,15 +1076,12 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, } if (ret < 0) goto free; - } end: if (rep_id_val) xmlFree(rep_id_val); if (rep_bandwidth_val) xmlFree(rep_bandwidth_val); - if (rep_framerate_val) - xmlFree(rep_framerate_val); return ret; enomem: From patchwork Sat Sep 19 16:36: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: 22500 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 169A34493ED for ; Sat, 19 Sep 2020 19:39:54 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E6BFB68B8E2; Sat, 19 Sep 2020 19:37:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6455968B877 for ; Sat, 19 Sep 2020 19:37:33 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id l15so8736901wmh.1 for ; Sat, 19 Sep 2020 09:37:33 -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=hNKUqWsPOpJiGUPHV8DBvYiQReLdN1cH6mMvxfGt45E=; b=EZo2/EojPR1B7yq5z2+mXzuYCE6Y+17wOsU2aFOUYyr/lU9yHoh8I0WDHmr+be1kza ISq89S9DnMntlWzJvvROjIDhbW3jo7NVSYCy9ZXmvdsrOozTtLNB8jE6Ash0i8G0h3+q Q/an68GKpcC+yUCu7Y2E5IKvFjRICSDXAFmCyaeHeIRq1QyvnbINq3EVss40Non+lKUS 72DtueSUhKME8Q2GPT52BKu0EivFfYbTbq5TQ3i1cyzl7Dut8VsD3mPh6ULcGzyQbh3T 3OnH9p6EHhyr/r8DiyTMgAo4BXfvg5mhjtmZHLEVMUVTLzbdeQClLPnQd+pPnn0U0wES LP1w== 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=hNKUqWsPOpJiGUPHV8DBvYiQReLdN1cH6mMvxfGt45E=; b=TBVXHNojRIwwJWA8yb5M4ptooSQyJhBENYpJyWaB2cmJe5xuXFEzIsp8xGIEQDD6ag ox7a88LqPHhaX4f/rcpGPs4Id1NoiPTM213TGn7SQMDZu29DmUx9encl6b1Mk7QyQh89 ckq2OCl4DupRLY1k+MQZ2TImg1euEokc8boSagSXlblvTZh5lTi6/nqK6W+oKYuqfmcM O2cEddHDC7ybmVJYi5ttgnsvrhbcFd1Xp03RZItdzYQIcbESXmlPyIAdS/G85Ym+oYmj 5LUcxea0J3avEdzt0U7MgJN2iZaL/b1DnvIm+Jg7lfYcxr9VsbtKNmsfba5zbIfL8XlO mKYw== X-Gm-Message-State: AOAM532JreJw8S3qUGyhePYrjtctnFdyQGqcgZgX/UkfZfy4JQPaVj8m Eg52lv+mshB6GZXCJbr5womGcQLV4TY= X-Google-Smtp-Source: ABdhPJxnRWbIOgH7PRSK0pH7wsU44WmY+Fb58NAe9wWresvTgR014WMeaNTiiB0LdYyBSGtxs/xQjA== X-Received: by 2002:a1c:9a57:: with SMTP id c84mr21050178wme.136.1600533452315; Sat, 19 Sep 2020 09:37:32 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:31 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:07 +0200 Message-Id: <20200919163610.1099233-18-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/21] avformat/dashdec: Remove redundant casts to const 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" Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 90 +++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 3b6ae29b1b..71c6b5cc1a 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -497,7 +497,7 @@ static char *get_content_url(xmlNodePtr *baseurl_nodes, ff_make_absolute_url(tmp_str, max_url_size, tmp_str, val); if (rep_id_val) { - url = av_strireplace(tmp_str, "$RepresentationID$", (const char*)rep_id_val); + url = av_strireplace(tmp_str, "$RepresentationID$", rep_id_val); if (!url) { goto end; } @@ -506,7 +506,7 @@ static char *get_content_url(xmlNodePtr *baseurl_nodes, if (rep_bandwidth_val && tmp_str[0] != '\0') { // free any previously assigned url before reassigning av_free(url); - url = av_strireplace(tmp_str, "$Bandwidth$", (const char*)rep_bandwidth_val); + url = av_strireplace(tmp_str, "$Bandwidth$", rep_bandwidth_val); if (!url) { goto end; } @@ -562,11 +562,11 @@ static enum AVMediaType get_content_type(xmlNodePtr node) attr = i ? "mimeType" : "contentType"; val = xmlGetProp(node, attr); if (val) { - if (av_stristr((const char *)val, "video")) { + if (av_stristr(val, "video")) { type = AVMEDIA_TYPE_VIDEO; - } else if (av_stristr((const char *)val, "audio")) { + } else if (av_stristr(val, "audio")) { type = AVMEDIA_TYPE_AUDIO; - } else if (av_stristr((const char *)val, "text")) { + } else if (av_stristr(val, "text")) { type = AVMEDIA_TYPE_SUBTITLE; } xmlFree(val); @@ -607,7 +607,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati int max_url_size = c ? c->max_url_size: MAX_URL_SIZE; int err; - if (!av_strcasecmp(fragmenturl_node->name, (const char *)"Initialization")) { + if (!av_strcasecmp(fragmenturl_node->name, "Initialization")) { initialization_val = xmlGetProp(fragmenturl_node, "sourceURL"); range_val = xmlGetProp(fragmenturl_node, "range"); if (initialization_val || range_val) { @@ -629,7 +629,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati return AVERROR(ENOMEM); } } - } else if (!av_strcasecmp(fragmenturl_node->name, (const char *)"SegmentURL")) { + } else if (!av_strcasecmp(fragmenturl_node->name, "SegmentURL")) { media_val = xmlGetProp(fragmenturl_node, "media"); range_val = xmlGetProp(fragmenturl_node, "mediaRange"); if (media_val || range_val) { @@ -667,7 +667,7 @@ static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representat char *val = NULL; int err; - if (!av_strcasecmp(fragment_timeline_node->name, (const char *)"S")) { + if (!av_strcasecmp(fragment_timeline_node->name, "S")) { struct timeline *tml = av_mallocz(sizeof(struct timeline)); if (!tml) { return AVERROR(ENOMEM); @@ -681,11 +681,11 @@ static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representat continue; } - if (!av_strcasecmp(attr->name, (const char *)"t")) { + if (!av_strcasecmp(attr->name, "t")) { tml->starttime = (int64_t)strtoll(val, NULL, 10); - } else if (!av_strcasecmp(attr->name, (const char *)"r")) { + } else if (!av_strcasecmp(attr->name, "r")) { tml->repeat =(int64_t) strtoll(val, NULL, 10); - } else if (!av_strcasecmp(attr->name, (const char *)"d")) { + } else if (!av_strcasecmp(attr->name, "d")) { tml->duration = (int64_t)strtoll(val, NULL, 10); } attr = attr->next; @@ -1044,7 +1044,7 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, } } } else { - av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id[%s] \n", (const char *)rep_id_val); + av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id[%s] \n", rep_id_val); goto free; } @@ -1126,17 +1126,17 @@ static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, node = xmlFirstElementChild(adaptionset_node); while (node) { - if (!av_strcasecmp(node->name, (const char *)"SegmentTemplate")) { + if (!av_strcasecmp(node->name, "SegmentTemplate")) { fragment_template_node = node; - } else if (!av_strcasecmp(node->name, (const char *)"ContentComponent")) { + } else if (!av_strcasecmp(node->name, "ContentComponent")) { content_component_node = node; - } else if (!av_strcasecmp(node->name, (const char *)"BaseURL")) { + } else if (!av_strcasecmp(node->name, "BaseURL")) { adaptionset_baseurl_node = node; - } else if (!av_strcasecmp(node->name, (const char *)"SegmentList")) { + } else if (!av_strcasecmp(node->name, "SegmentList")) { adaptionset_segmentlist_node = node; - } else if (!av_strcasecmp(node->name, (const char *)"SupplementalProperty")) { + } else if (!av_strcasecmp(node->name, "SupplementalProperty")) { adaptionset_supplementalproperty_node = node; - } else if (!av_strcasecmp(node->name, (const char *)"Representation")) { + } else if (!av_strcasecmp(node->name, "Representation")) { ret = parse_manifest_representation(s, url, node, adaptionset_node, mpd_baseurl_node, @@ -1258,7 +1258,7 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) } if (node->type != XML_ELEMENT_NODE || - av_strcasecmp(node->name, (const char *)"MPD")) { + av_strcasecmp(node->name, "MPD")) { ret = AVERROR_INVALIDDATA; av_log(s, AV_LOG_ERROR, "Unable to parse '%s' - wrong root node name[%s] type[%d]\n", url, node->name, (int)node->type); goto cleanup; @@ -1270,7 +1270,7 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) ret = AVERROR_INVALIDDATA; goto cleanup; } - if (!av_strcasecmp(val, (const char *)"dynamic")) + if (!av_strcasecmp(val, "dynamic")) c->is_live = 1; xmlFree(val); @@ -1278,29 +1278,29 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) while (attr) { val = xmlGetProp(node, attr->name); - if (!av_strcasecmp(attr->name, (const char *)"availabilityStartTime")) { - c->availability_start_time = get_utc_date_time_insec(s, (const char *)val); + if (!av_strcasecmp(attr->name, "availabilityStartTime")) { + c->availability_start_time = get_utc_date_time_insec(s, val); av_log(s, AV_LOG_TRACE, "c->availability_start_time = [%"PRId64"]\n", c->availability_start_time); - } else if (!av_strcasecmp(attr->name, (const char *)"availabilityEndTime")) { - c->availability_end_time = get_utc_date_time_insec(s, (const char *)val); + } else if (!av_strcasecmp(attr->name, "availabilityEndTime")) { + c->availability_end_time = get_utc_date_time_insec(s, val); av_log(s, AV_LOG_TRACE, "c->availability_end_time = [%"PRId64"]\n", c->availability_end_time); - } else if (!av_strcasecmp(attr->name, (const char *)"publishTime")) { - c->publish_time = get_utc_date_time_insec(s, (const char *)val); + } else if (!av_strcasecmp(attr->name, "publishTime")) { + c->publish_time = get_utc_date_time_insec(s, val); av_log(s, AV_LOG_TRACE, "c->publish_time = [%"PRId64"]\n", c->publish_time); - } else if (!av_strcasecmp(attr->name, (const char *)"minimumUpdatePeriod")) { - c->minimum_update_period = get_duration_insec(s, (const char *)val); + } else if (!av_strcasecmp(attr->name, "minimumUpdatePeriod")) { + c->minimum_update_period = get_duration_insec(s, val); av_log(s, AV_LOG_TRACE, "c->minimum_update_period = [%"PRId64"]\n", c->minimum_update_period); - } else if (!av_strcasecmp(attr->name, (const char *)"timeShiftBufferDepth")) { - c->time_shift_buffer_depth = get_duration_insec(s, (const char *)val); + } else if (!av_strcasecmp(attr->name, "timeShiftBufferDepth")) { + c->time_shift_buffer_depth = get_duration_insec(s, val); av_log(s, AV_LOG_TRACE, "c->time_shift_buffer_depth = [%"PRId64"]\n", c->time_shift_buffer_depth); - } else if (!av_strcasecmp(attr->name, (const char *)"minBufferTime")) { - c->min_buffer_time = get_duration_insec(s, (const char *)val); + } else if (!av_strcasecmp(attr->name, "minBufferTime")) { + c->min_buffer_time = get_duration_insec(s, val); av_log(s, AV_LOG_TRACE, "c->min_buffer_time = [%"PRId64"]\n", c->min_buffer_time); - } else if (!av_strcasecmp(attr->name, (const char *)"suggestedPresentationDelay")) { - c->suggested_presentation_delay = get_duration_insec(s, (const char *)val); + } else if (!av_strcasecmp(attr->name, "suggestedPresentationDelay")) { + c->suggested_presentation_delay = get_duration_insec(s, val); av_log(s, AV_LOG_TRACE, "c->suggested_presentation_delay = [%"PRId64"]\n", c->suggested_presentation_delay); - } else if (!av_strcasecmp(attr->name, (const char *)"mediaPresentationDuration")) { - c->media_presentation_duration = get_duration_insec(s, (const char *)val); + } else if (!av_strcasecmp(attr->name, "mediaPresentationDuration")) { + c->media_presentation_duration = get_duration_insec(s, val); av_log(s, AV_LOG_TRACE, "c->media_presentation_duration = [%"PRId64"]\n", c->media_presentation_duration); } attr = attr->next; @@ -1317,16 +1317,16 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) // at now we can handle only one period, with the longest duration node = xmlFirstElementChild(node); while (node) { - if (!av_strcasecmp(node->name, (const char *)"Period")) { + if (!av_strcasecmp(node->name, "Period")) { period_duration_sec = 0; period_start_sec = 0; attr = node->properties; while (attr) { val = xmlGetProp(node, attr->name); - if (!av_strcasecmp(attr->name, (const char *)"duration")) { - period_duration_sec = get_duration_insec(s, (const char *)val); - } else if (!av_strcasecmp(attr->name, (const char *)"start")) { - period_start_sec = get_duration_insec(s, (const char *)val); + if (!av_strcasecmp(attr->name, "duration")) { + period_duration_sec = get_duration_insec(s, val); + } else if (!av_strcasecmp(attr->name, "start")) { + period_start_sec = get_duration_insec(s, val); } attr = attr->next; xmlFree(val); @@ -1351,13 +1351,13 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) adaptionset_node = xmlFirstElementChild(period_node); while (adaptionset_node) { - if (!av_strcasecmp(adaptionset_node->name, (const char *)"BaseURL")) { + if (!av_strcasecmp(adaptionset_node->name, "BaseURL")) { period_baseurl_node = adaptionset_node; - } else if (!av_strcasecmp(adaptionset_node->name, (const char *)"SegmentTemplate")) { + } else if (!av_strcasecmp(adaptionset_node->name, "SegmentTemplate")) { period_segmenttemplate_node = adaptionset_node; - } else if (!av_strcasecmp(adaptionset_node->name, (const char *)"SegmentList")) { + } else if (!av_strcasecmp(adaptionset_node->name, "SegmentList")) { period_segmentlist_node = adaptionset_node; - } else if (!av_strcasecmp(adaptionset_node->name, (const char *)"AdaptationSet")) { + } else if (!av_strcasecmp(adaptionset_node->name, "AdaptationSet")) { parse_manifest_adaptationset(s, url, adaptionset_node, mpd_baseurl_node, period_baseurl_node, period_segmenttemplate_node, period_segmentlist_node); } adaptionset_node = xmlNextElementSibling(adaptionset_node); From patchwork Sat Sep 19 16:36:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22531 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c650:0:0:0:0:0 with SMTP id k77csp2088594ybf; Sat, 19 Sep 2020 09:40:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw639Ba0amdpusSZ1m0CK/nxusxKBEgU3FLWX7a30etTjvqrze4jigVZRUM9QWZ/sTH65qS X-Received: by 2002:adf:c64e:: with SMTP id u14mr42466646wrg.373.1600533609041; Sat, 19 Sep 2020 09:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600533609; cv=none; d=google.com; s=arc-20160816; b=0+c9c8aW2zT41QYaitv2axqmS0KCrZLtKVmLMIed1fmssPZ4U54FxsbAtFaVp5cQe1 N3NqtVKWlX+59g4/uCNiyX9OhBFbs1FcPhYJ9qcAgjdT6FFzQxXEbAot0xCrtsIC5k1k zYQ3ckp4FkmjYIVcJrj8aZhJJ9yCa0vWxRlfU0eJykl1KC4cFHVuYkHN3j+cz/emTydu CCNc/sWWQiFRPEJl6zGkW/QYWQOEu8iynt7G7EqNwOktr6mGykG4CT7WiGsWzuk2MOVc 9rm7h0SrqtgrceUiWYS6sw1h4BPdcGnZgQINL7bg+mtaWRuRq/Z1aEyOJdWsVyeLcZYq aDVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=pX+DLyJ9z8baEssYqEjtufE/gM1ShfbBuletAXBkDTA=; b=vuDYtnTTQ3hg2QcW1QDpB9ll+WD8iK9KEWi24BLIquaTecpcWChVc6jiGRyedxaYve QZgghOcKtO0g8YZcRED9ebMT0aIeN+OSZ5xbYQ4m/1wvGTJAquvibghnoOTKHoeMqsRk Jv7mel3TLMfXzwvOADnIe8zkUY6LQygI2Jwm0mk6cyWN/n4EB+GjAhCf+4mJyBJu4cQT 6Fb/LSTCSe/lxtlQFQKn2wVpFxqIB5Aelo2xe7FmaYYpJIwY7qZ/hiCt/UOGl19adJ+x W/zBYe75CfZleDZl4hXfS2K1ioZuT1mC3F6HKcjvpg/Fh4P+GTQdMhnZGIByZvNvpqze 7dLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=d3BjnAcH; 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 x16si6281512wmj.155.2020.09.19.09.40.08; Sat, 19 Sep 2020 09:40:09 -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=20161025 header.b=d3BjnAcH; 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 9C0F468B980; Sat, 19 Sep 2020 19:37:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D2F4468B7AB for ; Sat, 19 Sep 2020 19:37:34 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id z9so8462590wmk.1 for ; Sat, 19 Sep 2020 09:37:34 -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=Qbr59balKYXp8YRJmFp1qUTgu8aGRz1fYs/IDiSSCTI=; b=d3BjnAcH6+1cZWl0XyrOHCsHuXOBEdbr+M3pkkiaoFxFcsOaNEOtblVhgqeTNmnie9 0nzpFjfkMI9KEs39l8vNDoKglYWKFhpJRafKWxLsyU36dG+5tNAKdtL3qekYY2iQO5fM KpHs5nZOjVUz//Ktql7onWRwrpcbMqrkXxeK6gSe1bw2V/9WqW29TyUWm6YIqgXKSkar 1E0vmMFknxDmn7ED2yntce9glZpwduv68OhalnuqnZqjjSevxHL4iInrq1eW6x2xT2Gx TiJ2yfzvJ1CJnZwYwlFmbo85aTzi82YJ9GzsCMCMx/LmufBIzislAXOY8ElZ/1tIVPGQ Mnsg== 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=Qbr59balKYXp8YRJmFp1qUTgu8aGRz1fYs/IDiSSCTI=; b=WVVUch/jdYQVAgKfC+2FM9KBegWQKy7ZHKQfg7E09UKRvrukXeEf2VdWvWofVXt5I2 C4LrExqTl5W7WjBsYC3pkyw5h1I2zM4GqZBFP81Pf0XOL6BUumir/cvPyIbAWVmOtvtM okoFLWAE+jyY1/tsmeIowNQBEWLJPgV+cvfBgc2G4HeREhD8PL2GEl++p7rtl3H5p05K 1YcJI0jIIPJwihX1JnryolJMSGzTxu0xRLo3XWZm0CW2buro0sneVaRxk4bO+P4/ROW6 oWwIw0iWQmQMr9UoLMToL/una99FvuAz6aMUzPh/elcJRmSXWTeRb5StxoKZy7ILtQEF yLag== X-Gm-Message-State: AOAM530vCRNg4upP9NmDiBlZZ9fVQFOPohX9IgTKBADQRQh/lnPDrPMD yfR+59aImYpFFRqQdxa/WpvzFbHkoxI= X-Received: by 2002:a1c:4c0d:: with SMTP id z13mr20687641wmf.115.1600533453477; Sat, 19 Sep 2020 09:37:33 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:32 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:08 +0200 Message-Id: <20200919163610.1099233-19-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/21] avformat/dashdec: Cosmetics 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" X-TUID: gTJnyaPgAFd6 Content-Length: 38318 1. Perform the necessary reindentations after the last few commits. 2. Adapt switches to the ordinary indentation style. 3. Now that the effective lifetimes of the variables containing the freshly allocated strings used when parsing the representation are disjoint, the variables can be replaced by a single variable. Doing so has the advantage of making it more clear that these are throwaway variables, hence it has been done. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 498 +++++++++++++++++++++--------------------- 1 file changed, 245 insertions(+), 253 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 71c6b5cc1a..73740eb061 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -227,21 +227,21 @@ static uint32_t get_duration_insec(AVFormatContext *s, const char *duration) return 0; /* parser error */ } switch (type) { - case 'D': - days = (uint32_t)value; - break; - case 'H': - hours = (uint32_t)value; - break; - case 'M': - mins = (uint32_t)value; - break; - case 'S': - secs = (uint32_t)value; - break; - default: - // handle invalid type - break; + case 'D': + days = (uint32_t)value; + break; + case 'H': + hours = (uint32_t)value; + break; + case 'M': + mins = (uint32_t)value; + break; + case 'S': + secs = (uint32_t)value; + break; + default: + // handle invalid type + break; } ptr += size; } @@ -843,12 +843,6 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, xmlNodePtr segmentlists_tab[3]; xmlNodePtr fragment_timeline_node = NULL; xmlNodePtr fragment_templates_tab[5]; - char *duration_val = NULL; - char *presentation_timeoffset_val = NULL; - char *startnumber_val = NULL; - char *timescale_val = NULL; - char *initialization_val = NULL; - char *media_val = NULL; char *val = NULL; xmlNodePtr baseurl_nodes[4]; xmlNodePtr representation_node = node; @@ -869,213 +863,214 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, av_log(s, AV_LOG_VERBOSE, "Parsing '%s' - skipp not supported representation type\n", url); return 0; } - // convert selected representation to our internal struct - rep = av_mallocz(sizeof(struct representation)); - if (!rep) + + // convert selected representation to our internal struct + rep = av_mallocz(sizeof(struct representation)); + if (!rep) + return AVERROR(ENOMEM); + if (c->adaptionset_lang) { + rep->lang = av_strdup(c->adaptionset_lang); + if (!rep->lang) { + av_log(s, AV_LOG_ERROR, "alloc language memory failure\n"); + av_freep(&rep); return AVERROR(ENOMEM); - if (c->adaptionset_lang) { - rep->lang = av_strdup(c->adaptionset_lang); - if (!rep->lang) { - av_log(s, AV_LOG_ERROR, "alloc language memory failure\n"); - av_freep(&rep); - return AVERROR(ENOMEM); - } } - rep->parent = s; - representation_segmenttemplate_node = find_child_node_by_name(representation_node, "SegmentTemplate"); - representation_baseurl_node = find_child_node_by_name(representation_node, "BaseURL"); - representation_segmentlist_node = find_child_node_by_name(representation_node, "SegmentList"); - rep_id_val = xmlGetProp(representation_node, "id"); - rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth"); - - baseurl_nodes[0] = mpd_baseurl_node; - baseurl_nodes[1] = period_baseurl_node; - baseurl_nodes[2] = adaptionset_baseurl_node; - baseurl_nodes[3] = representation_baseurl_node; - - ret = resolve_content_path(s, url, &c->max_url_size, baseurl_nodes, 4); - c->max_url_size = aligned(c->max_url_size - + (rep_id_val ? strlen(rep_id_val) : 0) - + (rep_bandwidth_val ? strlen(rep_bandwidth_val) : 0)); - if (ret == AVERROR(ENOMEM) || ret == 0) - goto free; - if (representation_segmenttemplate_node || fragment_template_node || period_segmenttemplate_node) { - fragment_timeline_node = NULL; - fragment_templates_tab[0] = representation_segmenttemplate_node; - fragment_templates_tab[1] = adaptionset_segmentlist_node; - fragment_templates_tab[2] = fragment_template_node; - fragment_templates_tab[3] = period_segmenttemplate_node; - fragment_templates_tab[4] = period_segmentlist_node; - - initialization_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "initialization"); - if (initialization_val) { - rep->init_section = av_mallocz(sizeof(struct fragment)); - if (!rep->init_section) { - xmlFree(initialization_val); - goto enomem; - } - c->max_url_size = aligned(c->max_url_size + strlen(initialization_val)); - rep->init_section->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, initialization_val); - xmlFree(initialization_val); - if (!rep->init_section->url) - goto enomem; - rep->init_section->size = -1; - } - media_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "media"); - if (media_val) { - c->max_url_size = aligned(c->max_url_size + strlen(media_val)); - rep->url_template = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, media_val); - xmlFree(media_val); - } - presentation_timeoffset_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "presentationTimeOffset"); - if (presentation_timeoffset_val) { - rep->presentation_timeoffset = (int64_t) strtoll(presentation_timeoffset_val, NULL, 10); - av_log(s, AV_LOG_TRACE, "rep->presentation_timeoffset = [%"PRId64"]\n", rep->presentation_timeoffset); - xmlFree(presentation_timeoffset_val); - } - duration_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "duration"); - if (duration_val) { - rep->fragment_duration = (int64_t) strtoll(duration_val, NULL, 10); - av_log(s, AV_LOG_TRACE, "rep->fragment_duration = [%"PRId64"]\n", rep->fragment_duration); - xmlFree(duration_val); - } - timescale_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "timescale"); - if (timescale_val) { - rep->fragment_timescale = (int64_t) strtoll(timescale_val, NULL, 10); - av_log(s, AV_LOG_TRACE, "rep->fragment_timescale = [%"PRId64"]\n", rep->fragment_timescale); - xmlFree(timescale_val); - } - startnumber_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "startNumber"); - if (startnumber_val) { - rep->start_number = rep->first_seq_no = (int64_t) strtoll(startnumber_val, NULL, 10); - av_log(s, AV_LOG_TRACE, "rep->first_seq_no = [%"PRId64"]\n", rep->first_seq_no); - xmlFree(startnumber_val); - } - if (adaptionset_supplementalproperty_node) { - if (!av_strcasecmp(xmlGetProp(adaptionset_supplementalproperty_node,"schemeIdUri"), "http://dashif.org/guidelines/last-segment-number")) { - val = xmlGetProp(adaptionset_supplementalproperty_node,"value"); - if (!val) { - av_log(s, AV_LOG_ERROR, "Missing value attribute in adaptionset_supplementalproperty_node\n"); - } else { - rep->last_seq_no =(int64_t) strtoll(val, NULL, 10) - 1; - xmlFree(val); - } - } - } - - fragment_timeline_node = find_child_node_by_name(representation_segmenttemplate_node, "SegmentTimeline"); - - if (!fragment_timeline_node) - fragment_timeline_node = find_child_node_by_name(fragment_template_node, "SegmentTimeline"); - if (!fragment_timeline_node) - fragment_timeline_node = find_child_node_by_name(adaptionset_segmentlist_node, "SegmentTimeline"); - if (!fragment_timeline_node) - fragment_timeline_node = find_child_node_by_name(period_segmentlist_node, "SegmentTimeline"); - if (fragment_timeline_node) { - fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node); - while (fragment_timeline_node) { - ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node); - if (ret < 0) - goto free; - fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node); - } - } - } else if (representation_baseurl_node && !representation_segmentlist_node) { - seg = av_mallocz(sizeof(struct fragment)); - if (!seg) + } + rep->parent = s; + representation_segmenttemplate_node = find_child_node_by_name(representation_node, "SegmentTemplate"); + representation_baseurl_node = find_child_node_by_name(representation_node, "BaseURL"); + representation_segmentlist_node = find_child_node_by_name(representation_node, "SegmentList"); + rep_id_val = xmlGetProp(representation_node, "id"); + rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth"); + + baseurl_nodes[0] = mpd_baseurl_node; + baseurl_nodes[1] = period_baseurl_node; + baseurl_nodes[2] = adaptionset_baseurl_node; + baseurl_nodes[3] = representation_baseurl_node; + + ret = resolve_content_path(s, url, &c->max_url_size, baseurl_nodes, 4); + c->max_url_size = aligned(c->max_url_size + + (rep_id_val ? strlen(rep_id_val) : 0) + + (rep_bandwidth_val ? strlen(rep_bandwidth_val) : 0)); + if (ret == AVERROR(ENOMEM) || ret == 0) + goto free; + if (representation_segmenttemplate_node || fragment_template_node || period_segmenttemplate_node) { + fragment_timeline_node = NULL; + fragment_templates_tab[0] = representation_segmenttemplate_node; + fragment_templates_tab[1] = adaptionset_segmentlist_node; + fragment_templates_tab[2] = fragment_template_node; + fragment_templates_tab[3] = period_segmenttemplate_node; + fragment_templates_tab[4] = period_segmentlist_node; + + val = get_val_from_nodes_tab(fragment_templates_tab, 4, "initialization"); + if (val) { + rep->init_section = av_mallocz(sizeof(struct fragment)); + if (!rep->init_section) { + xmlFree(val); goto enomem; - ret = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg); - if (ret < 0) { - av_free(seg); - goto free; } - seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, NULL); - if (!seg->url) + c->max_url_size = aligned(c->max_url_size + strlen(val)); + rep->init_section->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, val); + xmlFree(val); + if (!rep->init_section->url) goto enomem; - seg->size = -1; - } else if (representation_segmentlist_node) { - // TODO: https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html - // http://www-itec.uni-klu.ac.at/dash/ddash/mpdGenerator.php?fragmentlength=15&type=full - xmlNodePtr fragmenturl_node = NULL; - segmentlists_tab[0] = representation_segmentlist_node; - segmentlists_tab[1] = adaptionset_segmentlist_node; - segmentlists_tab[2] = period_segmentlist_node; - - duration_val = get_val_from_nodes_tab(segmentlists_tab, 3, "duration"); - timescale_val = get_val_from_nodes_tab(segmentlists_tab, 3, "timescale"); - startnumber_val = get_val_from_nodes_tab(segmentlists_tab, 3, "startNumber"); - if (duration_val) { - rep->fragment_duration = (int64_t) strtoll(duration_val, NULL, 10); - av_log(s, AV_LOG_TRACE, "rep->fragment_duration = [%"PRId64"]\n", rep->fragment_duration); - xmlFree(duration_val); - } - if (timescale_val) { - rep->fragment_timescale = (int64_t) strtoll(timescale_val, NULL, 10); - av_log(s, AV_LOG_TRACE, "rep->fragment_timescale = [%"PRId64"]\n", rep->fragment_timescale); - xmlFree(timescale_val); - } - if (startnumber_val) { - rep->start_number = rep->first_seq_no = (int64_t) strtoll(startnumber_val, NULL, 10); - av_log(s, AV_LOG_TRACE, "rep->first_seq_no = [%"PRId64"]\n", rep->first_seq_no); - xmlFree(startnumber_val); + rep->init_section->size = -1; + } + val = get_val_from_nodes_tab(fragment_templates_tab, 4, "media"); + if (val) { + c->max_url_size = aligned(c->max_url_size + strlen(val)); + rep->url_template = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, val); + xmlFree(val); + } + val = get_val_from_nodes_tab(fragment_templates_tab, 4, "presentationTimeOffset"); + if (val) { + rep->presentation_timeoffset = (int64_t) strtoll(val, NULL, 10); + av_log(s, AV_LOG_TRACE, "rep->presentation_timeoffset = [%"PRId64"]\n", rep->presentation_timeoffset); + xmlFree(val); + } + val = get_val_from_nodes_tab(fragment_templates_tab, 4, "duration"); + if (val) { + rep->fragment_duration = (int64_t) strtoll(val, NULL, 10); + av_log(s, AV_LOG_TRACE, "rep->fragment_duration = [%"PRId64"]\n", rep->fragment_duration); + xmlFree(val); + } + val = get_val_from_nodes_tab(fragment_templates_tab, 4, "timescale"); + if (val) { + rep->fragment_timescale = (int64_t) strtoll(val, NULL, 10); + av_log(s, AV_LOG_TRACE, "rep->fragment_timescale = [%"PRId64"]\n", rep->fragment_timescale); + xmlFree(val); + } + val = get_val_from_nodes_tab(fragment_templates_tab, 4, "startNumber"); + if (val) { + rep->start_number = rep->first_seq_no = (int64_t) strtoll(val, NULL, 10); + av_log(s, AV_LOG_TRACE, "rep->first_seq_no = [%"PRId64"]\n", rep->first_seq_no); + xmlFree(val); + } + if (adaptionset_supplementalproperty_node) { + if (!av_strcasecmp(xmlGetProp(adaptionset_supplementalproperty_node,"schemeIdUri"), "http://dashif.org/guidelines/last-segment-number")) { + val = xmlGetProp(adaptionset_supplementalproperty_node,"value"); + if (!val) { + av_log(s, AV_LOG_ERROR, "Missing value attribute in adaptionset_supplementalproperty_node\n"); + } else { + rep->last_seq_no =(int64_t) strtoll(val, NULL, 10) - 1; + xmlFree(val); + } } + } - fragmenturl_node = xmlFirstElementChild(representation_segmentlist_node); - while (fragmenturl_node) { - ret = parse_manifest_segmenturlnode(s, rep, fragmenturl_node, - baseurl_nodes, - rep_id_val, - rep_bandwidth_val); - if (ret < 0) - goto free; - fragmenturl_node = xmlNextElementSibling(fragmenturl_node); - } + fragment_timeline_node = find_child_node_by_name(representation_segmenttemplate_node, "SegmentTimeline"); + if (!fragment_timeline_node) + fragment_timeline_node = find_child_node_by_name(fragment_template_node, "SegmentTimeline"); + if (!fragment_timeline_node) fragment_timeline_node = find_child_node_by_name(adaptionset_segmentlist_node, "SegmentTimeline"); - if (!fragment_timeline_node) - fragment_timeline_node = find_child_node_by_name(period_segmentlist_node, "SegmentTimeline"); - if (fragment_timeline_node) { - fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node); - while (fragment_timeline_node) { - ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node); - if (ret < 0) - goto free; - fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node); - } + if (!fragment_timeline_node) + fragment_timeline_node = find_child_node_by_name(period_segmentlist_node, "SegmentTimeline"); + if (fragment_timeline_node) { + fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node); + while (fragment_timeline_node) { + ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node); + if (ret < 0) + goto free; + fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node); } - } else { - av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id[%s] \n", rep_id_val); + } + } else if (representation_baseurl_node && !representation_segmentlist_node) { + seg = av_mallocz(sizeof(struct fragment)); + if (!seg) + goto enomem; + ret = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg); + if (ret < 0) { + av_free(seg); goto free; } + seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, NULL); + if (!seg->url) + goto enomem; + seg->size = -1; + } else if (representation_segmentlist_node) { + // TODO: https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html + // http://www-itec.uni-klu.ac.at/dash/ddash/mpdGenerator.php?fragmentlength=15&type=full + xmlNodePtr fragmenturl_node = NULL; + segmentlists_tab[0] = representation_segmentlist_node; + segmentlists_tab[1] = adaptionset_segmentlist_node; + segmentlists_tab[2] = period_segmentlist_node; + + val = get_val_from_nodes_tab(segmentlists_tab, 3, "duration"); + if (val) { + rep->fragment_duration = (int64_t) strtoll(val, NULL, 10); + av_log(s, AV_LOG_TRACE, "rep->fragment_duration = [%"PRId64"]\n", rep->fragment_duration); + xmlFree(val); + } + val = get_val_from_nodes_tab(segmentlists_tab, 3, "timescale"); + if (val) { + rep->fragment_timescale = (int64_t) strtoll(val, NULL, 10); + av_log(s, AV_LOG_TRACE, "rep->fragment_timescale = [%"PRId64"]\n", rep->fragment_timescale); + xmlFree(val); + } + val = get_val_from_nodes_tab(segmentlists_tab, 3, "startNumber"); + if (val) { + rep->start_number = rep->first_seq_no = (int64_t) strtoll(val, NULL, 10); + av_log(s, AV_LOG_TRACE, "rep->first_seq_no = [%"PRId64"]\n", rep->first_seq_no); + xmlFree(val); + } - if (rep->fragment_duration > 0 && !rep->fragment_timescale) - rep->fragment_timescale = 1; - rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0; - strncpy(rep->id, rep_id_val ? rep_id_val : "", sizeof(rep->id)); - rep->framerate = av_make_q(0, 0); - if (type == AVMEDIA_TYPE_VIDEO) { - char *rep_framerate_val = xmlGetProp(representation_node, "frameRate"); - if (rep_framerate_val) { - ret = av_parse_video_rate(&rep->framerate, rep_framerate_val); - if (ret < 0) - av_log(s, AV_LOG_VERBOSE, "Ignoring invalid frame rate '%s'\n", rep_framerate_val); - xmlFree(rep_framerate_val); - } - } + fragmenturl_node = xmlFirstElementChild(representation_segmentlist_node); + while (fragmenturl_node) { + ret = parse_manifest_segmenturlnode(s, rep, fragmenturl_node, + baseurl_nodes, + rep_id_val, + rep_bandwidth_val); + if (ret < 0) + goto free; + fragmenturl_node = xmlNextElementSibling(fragmenturl_node); + } - switch (type) { - case AVMEDIA_TYPE_VIDEO: - ret = av_dynarray_add_nofree(&c->videos, &c->n_videos, rep); - break; - case AVMEDIA_TYPE_AUDIO: - ret = av_dynarray_add_nofree(&c->audios, &c->n_audios, rep); - break; - case AVMEDIA_TYPE_SUBTITLE: - ret = av_dynarray_add_nofree(&c->subtitles, &c->n_subtitles, rep); - break; + fragment_timeline_node = find_child_node_by_name(adaptionset_segmentlist_node, "SegmentTimeline"); + if (!fragment_timeline_node) + fragment_timeline_node = find_child_node_by_name(period_segmentlist_node, "SegmentTimeline"); + if (fragment_timeline_node) { + fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node); + while (fragment_timeline_node) { + ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node); + if (ret < 0) + goto free; + fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node); } + } + } else { + av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id[%s] \n", rep_id_val); + goto free; + } + + if (rep->fragment_duration > 0 && !rep->fragment_timescale) + rep->fragment_timescale = 1; + rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0; + strncpy(rep->id, rep_id_val ? rep_id_val : "", sizeof(rep->id)); + rep->framerate = av_make_q(0, 0); + if (type == AVMEDIA_TYPE_VIDEO) { + char *rep_framerate_val = xmlGetProp(representation_node, "frameRate"); + if (rep_framerate_val) { + ret = av_parse_video_rate(&rep->framerate, rep_framerate_val); if (ret < 0) - goto free; + av_log(s, AV_LOG_VERBOSE, "Ignoring invalid frame rate '%s'\n", rep_framerate_val); + xmlFree(rep_framerate_val); + } + } + + switch (type) { + case AVMEDIA_TYPE_VIDEO: + ret = av_dynarray_add_nofree(&c->videos, &c->n_videos, rep); + break; + case AVMEDIA_TYPE_AUDIO: + ret = av_dynarray_add_nofree(&c->audios, &c->n_audios, rep); + break; + case AVMEDIA_TYPE_SUBTITLE: + ret = av_dynarray_add_nofree(&c->subtitles, &c->n_subtitles, rep); + break; + } + if (ret < 0) + goto free; end: if (rep_id_val) @@ -1901,11 +1896,8 @@ static int reopen_demux_for_component(AVFormatContext *s, struct representation pls->ctx = NULL; goto fail; } - if (c->is_live) { - ffio_init_context(&pls->pb, avio_ctx_buffer , INITIAL_BUFFER_SIZE, 0, pls, read_data, NULL, NULL); - } else { - ffio_init_context(&pls->pb, avio_ctx_buffer , INITIAL_BUFFER_SIZE, 0, pls, read_data, NULL, seek_data); - } + ffio_init_context(&pls->pb, avio_ctx_buffer , INITIAL_BUFFER_SIZE, 0, + pls, read_data, NULL, c->is_live ? NULL : seek_data); pls->pb.seekable = 0; if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0) @@ -2119,45 +2111,45 @@ static int dash_read_header(AVFormatContext *s) } /* Create a program */ - program = av_new_program(s, 0); - if (!program) { - ret = AVERROR(ENOMEM); - goto fail; - } + program = av_new_program(s, 0); + if (!program) { + ret = AVERROR(ENOMEM); + goto fail; + } - for (i = 0; i < c->n_videos; i++) { - rep = c->videos[i]; - av_program_add_stream_index(s, 0, rep->stream_index); - rep->assoc_stream = s->streams[rep->stream_index]; - if (rep->bandwidth > 0) - av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0); - if (rep->id[0]) - av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); - } - for (i = 0; i < c->n_audios; i++) { - rep = c->audios[i]; - av_program_add_stream_index(s, 0, rep->stream_index); - rep->assoc_stream = s->streams[rep->stream_index]; - if (rep->bandwidth > 0) - av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0); - if (rep->id[0]) - av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); - if (rep->lang) { - av_dict_set(&rep->assoc_stream->metadata, "language", rep->lang, 0); - av_freep(&rep->lang); - } + for (i = 0; i < c->n_videos; i++) { + rep = c->videos[i]; + av_program_add_stream_index(s, 0, rep->stream_index); + rep->assoc_stream = s->streams[rep->stream_index]; + if (rep->bandwidth > 0) + av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0); + if (rep->id[0]) + av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); + } + for (i = 0; i < c->n_audios; i++) { + rep = c->audios[i]; + av_program_add_stream_index(s, 0, rep->stream_index); + rep->assoc_stream = s->streams[rep->stream_index]; + if (rep->bandwidth > 0) + av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0); + if (rep->id[0]) + av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); + if (rep->lang) { + av_dict_set(&rep->assoc_stream->metadata, "language", rep->lang, 0); + av_freep(&rep->lang); } - for (i = 0; i < c->n_subtitles; i++) { - rep = c->subtitles[i]; - av_program_add_stream_index(s, 0, rep->stream_index); - rep->assoc_stream = s->streams[rep->stream_index]; - if (rep->id[0]) - av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); - if (rep->lang) { - av_dict_set(&rep->assoc_stream->metadata, "language", rep->lang, 0); - av_freep(&rep->lang); - } + } + for (i = 0; i < c->n_subtitles; i++) { + rep = c->subtitles[i]; + av_program_add_stream_index(s, 0, rep->stream_index); + rep->assoc_stream = s->streams[rep->stream_index]; + if (rep->id[0]) + av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); + if (rep->lang) { + av_dict_set(&rep->assoc_stream->metadata, "language", rep->lang, 0); + av_freep(&rep->lang); } + } return 0; fail: From patchwork Sat Sep 19 16:36:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22501 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 11C984496B7 for ; Sat, 19 Sep 2020 19:40:14 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0653D68B905; Sat, 19 Sep 2020 19:37:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8A33868B893 for ; Sat, 19 Sep 2020 19:37:35 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id x23so8096019wmi.3 for ; Sat, 19 Sep 2020 09:37:35 -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=R3VjaVZEWcJJ1F8w5QyHUnQyIo1Swp3CCqr8soNXawo=; b=AXx44aV96t+iJq9SHzQb9QuWJUgbSiG1RQGXA171dYnx8L9dtD3Ul/qUiExYetYZZ2 mQlTjeS+6XyuLULDgWVtWDJlFa/IqHfHu28i9CyyQNZnC5F1hesM4AbfUgA4lvVaV6G1 /XkIOdJysUc/KHgv21vLIroYaxqE2XsKz49INqXhXc97+FiETxHuSzlZkUC3DQK/Kd4t Xwxo35H1W8Gg8WBw0AkJaXW+iwrwwQgrH/UEiIdYbKEdQoP1F95s5rIya4lQMjKVvdGd PGWM4VgEE749S1du10HimjnleZNAEnEFRuMmk8zQ7sY7x2jgylGbut9+2NKu+yj2enab TYew== 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=R3VjaVZEWcJJ1F8w5QyHUnQyIo1Swp3CCqr8soNXawo=; b=n+dsngsQeLIid4Dh87gHzVoMxaUxiiNnxFjx2h2tMGWqdzZ7j9Mr/Y/Coz1buMtvaN xm+tEMNyABo66ZdJgw1uB6xgqXIFdz29LFBCjz4t/xFhyaGTeClPqW3d5B/NcMNn/KPA g+eJfFxEiNMMK98Okfb05UGqYY+QD82j8KI78TCP8BZhRVuZGB16ylrdhZE3CZ22YD0/ zs0rj61RiA5OXN3eELVeIVnml259uaofsAHC8q8sPxwRqiVwAGqeOvPmYQYYo8hKooew G7uUDDHr08qrMViENa8VoUaXrfgUB7336onEFvdXK42yyeVGbeQ7egdDIoUlV0o4psPD Vl/A== X-Gm-Message-State: AOAM533TNIu3ny3hrP029R7j6gh2p7X6DDV3DMWnQff2nAyIqSqTeoWY jo1MLu+SP4nX56bsVUu7I6j/Tja/yaA= X-Google-Smtp-Source: ABdhPJzIrH8zbtxJqRZ5NMduqrYXiTZl+xeegzjRHBRL+sTp+7wQD/4Q3Il8xEXBMbgSVKwcx3kkaQ== X-Received: by 2002:a1c:6145:: with SMTP id v66mr22138999wmb.171.1600533454509; Sat, 19 Sep 2020 09:37:34 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:33 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:09 +0200 Message-Id: <20200919163610.1099233-20-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/21] avformat/dashdec: Fix memleak 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" get_content_url() allocates two buffers for temporary strings and when one of them couldn't be allocated, it simply returns, although one of the two allocations could have succeeded and would leak in this scenario. This can be fixed by avoiding one of the temporary buffers. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 73740eb061..be67192b14 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -472,11 +472,9 @@ static char *get_content_url(xmlNodePtr *baseurl_nodes, char *text; char *url = NULL; char *tmp_str = av_mallocz(max_url_size); - char *tmp_str_2 = av_mallocz(max_url_size); - if (!tmp_str || !tmp_str_2) { + if (!tmp_str) return NULL; - } for (i = 0; i < n_baseurl_nodes; ++i) { if (baseurl_nodes[i] && @@ -485,9 +483,7 @@ static char *get_content_url(xmlNodePtr *baseurl_nodes, text = xmlNodeGetContent(baseurl_nodes[i]->children); if (text) { memset(tmp_str, 0, max_url_size); - memset(tmp_str_2, 0, max_url_size); - ff_make_absolute_url(tmp_str_2, max_url_size, tmp_str, text); - av_strlcpy(tmp_str, tmp_str_2, max_url_size); + ff_make_absolute_url(tmp_str, max_url_size, "", text); xmlFree(text); } } @@ -513,7 +509,6 @@ static char *get_content_url(xmlNodePtr *baseurl_nodes, } end: av_free(tmp_str); - av_free(tmp_str_2); return url; } From patchwork Sat Sep 19 16:36:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22502 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 452AF4496B7 for ; Sat, 19 Sep 2020 19:40:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C505D68B965; Sat, 19 Sep 2020 19:37:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 89D7F68B71E for ; Sat, 19 Sep 2020 19:37:36 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id e11so8747338wme.0 for ; Sat, 19 Sep 2020 09:37:36 -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=0fMb+cExjxKvNrQGHUgmZnINmBqgYOMHM2NL5nOb/vU=; b=OKqVfWRwpjWSir/l4586tNgtuFKRdscH12ySXOS1ux5EFrZll3TrAFENsVu5ijaFlh +Pu3ZuP3FRAfbpriTbyRAeHSLNdffgj5csl36R/DiWy5g2tXeiVRU1gOx5zNKMWF5XXF jux0gD1lMiOlh4X+BjMlsvc7G/JoPjDDWbwDLKAQxi3Y+oFKGePv0BMmTiKAFI/sp2wE VfzhbcW67QNJ5lm/t4F5upQfGzR3TgUwlFA68xqcx3GzMMBDpyGfaolSzLg5XEnxiYKO eHrt146KDPR7YDyZ2bipNHHYoqQNE0J4AfMuSNOpxHqtbi3lBLby8k8vJc+hxMFhTHkg 9I7A== 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=0fMb+cExjxKvNrQGHUgmZnINmBqgYOMHM2NL5nOb/vU=; b=T+kGeqLH7q3vE2hBoxWqpSyAOZNwjRr5N3huWBDS9+E2rvEhvO8a7HUlhXjpAilobG sKjw/RSW4wnzEbkXXak++pDMVkbcTN9oiUh11Xn6B3gs47ZC2Xu0JVPDPuYyAFsVvd8Y ED+/ArJEaRzcjfPZxKyA4gyIDafWkzkEDxQrpiCrLyP2LinW1QEgpJR7mhk26O9UYN+P 1XN8dT+zF/FMJygZioXZcUkT2AsfCjqsHJK+9/2uPVOps2VjWZhBzOJLWFWAxoULHD0g mu4oTNVHyLIxKufuUTx9DUF/sWEzWBpYUNu3PvevfSpCt9Mlz4FCleybWOKLoh33FpSd jfAw== X-Gm-Message-State: AOAM531eau3TLxXqVu/Jq2nUObizcGkkGszQnLjaup9h2WsQM1I94li8 v+XBbF443/XonQ6eA/fXDN0UmdLfdbs= X-Google-Smtp-Source: ABdhPJyuRX/XkZ3J4OIPWrsFfRD28XMzKYt2q/LDQ3jFwY0zf6E/VFpZvB8i+6xtzOCyS2bU6MynNg== X-Received: by 2002:a1c:e108:: with SMTP id y8mr21291258wmg.179.1600533455401; Sat, 19 Sep 2020 09:37:35 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:34 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:10 +0200 Message-Id: <20200919163610.1099233-21-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/21] avformat/dashdec: Avoid duplicating string 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" Signed-off-by: Andreas Rheinhardt --- There is still stuff left to fix in this demuxer after this patchset: 1. resolve_content_path() is in bad shape; i.e. it can try to read str[-1]. 2. One can get a crash in get_current_fragment() (or rather in ff_dash_fill_tmpl_params()) when one has a representation without fragment and without fragment/url template. 3. When one has a mismatch between old and new manifests in refresh_manifest(), the old representations leak. One could fix this by freeing the new representations and restoring the old ones, but this feels wrong; freeing the old ones is not possible, because refresh_manifests() is called indirectly by the read_packet function of an AVFormatContext associated with an old representation, so freeing the old representations would free the AVIOContext from within its read_packet function. This would lead to use-after-frees. libavformat/dashdec.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index be67192b14..747b4e92e3 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -1183,7 +1183,6 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) DASHContext *c = s->priv_data; int ret = 0; int close_in = 0; - uint8_t *new_url = NULL; int64_t filesize = 0; AVBPrint buf; AVDictionary *opts = NULL; @@ -1212,11 +1211,8 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) return ret; } - if (av_opt_get(in, "location", AV_OPT_SEARCH_CHILDREN, &new_url) >= 0) { - c->base_url = av_strdup(new_url); - } else { + if (av_opt_get(in, "location", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&c->base_url) < 0) c->base_url = av_strdup(url); - } filesize = avio_size(in); filesize = filesize > 0 ? filesize : DEFAULT_MANIFEST_SIZE; @@ -1359,7 +1355,6 @@ cleanup: xmlFreeNode(mpd_baseurl_node); } - av_free(new_url); av_bprint_finalize(&buf, NULL); if (close_in) { avio_close(in);