From patchwork Thu Aug 24 23:15:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 4824 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp28953jao; Thu, 24 Aug 2017 16:16:05 -0700 (PDT) X-Received: by 10.28.128.214 with SMTP id b205mr152112wmd.128.1503616565569; Thu, 24 Aug 2017 16:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503616565; cv=none; d=google.com; s=arc-20160816; b=YBJdP9HWGz32G+RF1EQ72WV10fgZwm7ZWKWbUurQV3sceZB390O8Yd6wfrHOW/73Im wVc/OLoU0SUTuPw6oQiHl891OoHKfS+Sh8XRaX0jTkH8+sGTqn4hbzi9qD/YJHOYQwKT tquIL4DbW5qoSIZkCVMfAMwPYIVXlvo8B8qYzRnYtlHpteqwJnzf7YbFFLFUHajOY6eZ XkHEeRpPUOqlrHM4148hxyO6wZpKxYDUUsfmkmtick87rMvovg3emgRdmRknDSwhZ6YC OeZ8KS0//UKF46R4orbuFef0yE9caA9jV9rYJz0Ii4uUwF1fdKTBeaZO+ebde+dPha/n vC3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=00HTLEVYZbMn1yDBhzpfmpbzMDgw2skyR2OHSVzc+PI=; b=LKcgn3dPW3jsho3+lLCcptCAlGy35SpNCAenLdtaoMQHwPbQiyoLBvL++bL1Ldm3ps MJlpCQtl/OgJxNYA0H6LFKiNYRPnybdsHwugM7lVR4ZJkXSUvZxfPt2795XHfgj2DLIV VQsjNW9UAupp+313vbpRSmanqOvOb0tqlUUXXU0nuPKSNCdLJD6ucbEVamKBXqgTSK6s HxkqSoGh5YJ3nZdb1zgI5CEuuAmk8ArwxvwFxXeixPzyUCoB1jgg5HyiIeBr8664YQW8 rvFzIqxyACBAOheKzcHe0WcX3pvX9F0SeDKCykThyGRZh46StYc+5cA51nWX+OgYaNoz lmRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y20si4479426wry.450.2017.08.24.16.16.05; Thu, 24 Aug 2017 16:16:05 -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; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 97A24689257; Fri, 25 Aug 2017 02:15:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe02-3.mx.upcmail.net (vie01a-dmta-pe02-3.mx.upcmail.net [62.179.121.159]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA5CB68826E for ; Fri, 25 Aug 2017 02:15:34 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dl1Lj-0005xt-5h for ffmpeg-devel@ffmpeg.org; Fri, 25 Aug 2017 01:15:43 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id 1BFf1w0030S5wYM01BFgeA; Fri, 25 Aug 2017 01:15:40 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 25 Aug 2017 01:15:32 +0200 Message-Id: <20170824231532.16002-6-michael@niedermayer.cc> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170824231532.16002-1-michael@niedermayer.cc> References: <20170824231532.16002-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 6/6] avformat/hls: Fix DoS due to 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes: loop.m3u The max iteration count of 10000 is arbitrary and ideas for a better solution are welcome Found-by: Xiaohei and Wangchu from Alibaba Security Team Signed-off-by: Michael Niedermayer --- libavformat/hls.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavformat/hls.c b/libavformat/hls.c index 01731bd36b..26f4ebd965 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -1263,6 +1263,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size) HLSContext *c = v->parent->priv_data; int ret, i; int just_opened = 0; + int reload_count = 0; restart: if (!v->needed) @@ -1294,6 +1295,9 @@ restart: reload_interval = default_reload_interval(v); reload: + reload_count++; + if (reload_count > 10000) + return AVERROR_EOF; if (!v->finished && av_gettime_relative() - v->last_load_time >= reload_interval) { if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) {