From patchwork Mon May 18 03:30:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19731 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 4079944AFD4 for ; Mon, 18 May 2020 06:31:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 295D568A485; Mon, 18 May 2020 06:31:16 +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 E4A0968A3DF for ; Mon, 18 May 2020 06:31:07 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id e16so10017057wra.7 for ; Sun, 17 May 2020 20:31:07 -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=vVEZrE8zcAphF5+v9XMmffvC90xDv7o5N995LQmv8eg=; b=U70W3DQH9b9jYOuMSb7anodRQxeMdjD+Qb0H9sD5YcsecwiYJ267M7dwIK3BdNTjYA nmTUVqBJhROqMZJjItJls79FZ43mN+PVtz5Bp4aAKU0ZYS4iEAnuke5KAPoVaMhbBMX7 R/uvxqj+qiJ8bEeNEGHyJRiu/xYrkL8jT8CWNnyp0fLXwZius24fHppbN8KQSpRbYuwT vvz+wnFpUZSly/5hmJKl0D3fTHdG1xLAjr44bMK1zriAnlNAOd+Ks2lIWl2CC8QMwq2P kit6k5cdXFoenoi3NyZuoyzLb/Mo18/2COSkLY3zn2u54QKVOoiKAr4KVZqJt7gwQkfb pWSQ== 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=vVEZrE8zcAphF5+v9XMmffvC90xDv7o5N995LQmv8eg=; b=aUSbe0tWqaBTDfKTZesoO7Skdc87P09TPpjquDiDLj/NcsKmIIab9VoSJomg1xlZrV 1MFSe26OCKvkcr918XTMctpgRAgMZA7PiSEwMAXwbQQLf20dsJFP7TP1rBZVtq+V9Olb pY3492uC/yit+EjGSWRGbkh6ewvFJk7WDquBXlygFS4JCoaTsfwTS99J82NgDoXJuzP5 cAYnr7iHUADD41ZCDX/tzidMelkwCS1UihwVGQ8VXNeicNB4Q4Z/PTUPnEKV+v5S8AZW gz6zh86RhII7vlD8hDzIzaaxBtmEKiEIiuBN5zsBIy3BVasdE0uGVMpEnuhP8l3Kcohi KJsg== X-Gm-Message-State: AOAM533DFsPvn/w1Iij7VZLCRzBqaL9+FalLzdc1hXRxosXk+4lK5+X4 c0u5lfcrcidIolc7+NAXqJ912kLS X-Google-Smtp-Source: ABdhPJzH32Xx7Tavoo78zDNBTA2U4P8eL7OWKqKF+3R4HzIb4v32lMo9MsO0rdzxngref8/Q6pZLRQ== X-Received: by 2002:a5d:61c3:: with SMTP id q3mr17140669wrv.405.1589772666980; Sun, 17 May 2020 20:31:06 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id a21sm1011151wmm.7.2020.05.17.20.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2020 20:31:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 05:30:31 +0200 Message-Id: <20200518033033.27347-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200518033033.27347-1-andreas.rheinhardt@gmail.com> References: <20200518033033.27347-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avformat/webmdashenc: Remove possibility of infinite loop 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 WebM DASH manifest muxer uses a loop to parse the adaptation_sets string (which is given by the user and governs which AVStreams are mapped to what adaptation set) and the very beginning of this loop is "if (*p == ' ') continue;". This of course leads to an infinite loop if the condition is true. It is true if e.g. the string begins with ' ' or if there are more than one ' ' between different adaptation set groups. To fix this, the parsing process has been modified to consume the space if it is at a place where it can legitimately occur, i.e. when a new adaptation set group is expected. The latter restriction implies that an error is returned if a space exists where none is allowed to exist. Signed-off-by: Andreas Rheinhardt --- libavformat/webmdashenc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c index 250c8ca3ad..fd07b3e34a 100644 --- a/libavformat/webmdashenc.c +++ b/libavformat/webmdashenc.c @@ -438,9 +438,10 @@ static int parse_adaptation_sets(AVFormatContext *s) // syntax id=0,streams=0,1,2 id=1,streams=3,4 and so on state = new_set; while (p < w->adaptation_sets + strlen(w->adaptation_sets)) { - if (*p == ' ') + if (state == new_set && *p == ' ') { + p++; continue; - else if (state == new_set && !strncmp(p, "id=", 3)) { + } else if (state == new_set && !strncmp(p, "id=", 3)) { void *mem = av_realloc(w->as, sizeof(*w->as) * (w->nb_as + 1)); const char *comma; if (mem == NULL)