From patchwork Fri Aug 25 23:26:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 4844 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp689433jao; Fri, 25 Aug 2017 16:27:12 -0700 (PDT) X-Received: by 10.223.169.198 with SMTP id b64mr37326wrd.325.1503703631924; Fri, 25 Aug 2017 16:27:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503703631; cv=none; d=google.com; s=arc-20160816; b=RdI8MI9azbcCVO28HpqO6ceeAYor9CgYMZXMGdCqh6JjalQskanKu4Evrdoxtkqn7D eWk/uPl3CUjm92C88DfRLKmhxnffCXZHLw+P6PdgFFY2Fh2qDiIgKsVPJLWU4Yd4jhgc dXpP8THeni3AIb/qfszFdonI7fenrhdQ7FPQxI25LZuSAVdQvGLKw9Va0+W5yaCN+vu7 YMbRa1Ai1m23g/LlKsUHNPdwUa+9JFH5xYHzCv2TzhuK1SH3h9dP98AGM39ptbjHO+pN vWEJBXtkpyjb9lQeVzo+2xkJBREE0DSbaiKMxTmLhmTvhK0udmXt8sRteWE7UqcGodpA +8gg== 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:message-id:date:to:from:delivered-to :arc-authentication-results; bh=UMiHGzMyIPWqvFq2IJ1BCZJNPb+dgA86RQzt82BHPvQ=; b=dDegK8e0ly3Fzz1a/ctzeHReS9eTK5rHs3VSnGLQ6PiOA21Cfd5D74rvjg2eFvmX5R xd0lVQN6vFMTgpteXr2W5gbCcsNcyh5uCzOMDpsHwDCxlYl8TKz4qYEdiSjo3c358pZv 3cGNDJ7lIqMdGzN3EVUQnZc4wfZwHUj1XQadOHoFJXRQMDz3VGU8Kkv9PJ5Ly7K2afFB 0x93XnN1WPrbLVAJxyjklG8hnlqMm0YnnG5I98zMYcWei00RuyghGjg5IGvAHh6LohL9 tylxVJC2D48+6t/KbKnKxiYVVyS9Aj/hoTrqJyXFURhr5oSDs7Am7DYOcGGEyVuN3FSw lSsg== 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 q193si2135766wme.99.2017.08.25.16.27.11; Fri, 25 Aug 2017 16:27:11 -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 52A19689A87; Sat, 26 Aug 2017 02:27:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe04-2.mx.upcmail.net (vie01a-dmta-pe04-2.mx.upcmail.net [62.179.121.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D359B689756 for ; Sat, 26 Aug 2017 02:26:53 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe04.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dlO0D-0001Na-Uq for ffmpeg-devel@ffmpeg.org; Sat, 26 Aug 2017 01:27:01 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id 1bSz1w00f0S5wYM01bT0eJ; Sat, 26 Aug 2017 01:27:00 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 26 Aug 2017 01:26:58 +0200 Message-Id: <20170825232658.9495-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.14.1 Subject: [FFmpeg-devel] [PATCH] 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 default max iteration count of 1000 is arbitrary and ideas for a better solution are welcome Found-by: Xiaohei and Wangchu from Alibaba Security Team Signed-off-by: Michael Niedermayer --- doc/demuxers.texi | 18 ++++++++++++++++++ libavformat/hls.c | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/doc/demuxers.texi b/doc/demuxers.texi index 29a23d48b2..ba4bb51177 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -300,6 +300,24 @@ used to end the output video at the length of the shortest input file, which in this case is @file{input.mp4} as the GIF in this example loops infinitely. +@section hls + +HLS demuxer + +It accepts the following options: + +@table @option +@item live_start_index +segment index to start live streams at (negative values are from the end). + +@item allowed_extensions +',' seperated list of file extensions that hls is allowed to access. + +@item max_reload +Maximum number of times a insufficient list is attempted to be reloaded. +Default value is 1000. +@end table + @section image2 Image file demuxer. diff --git a/libavformat/hls.c b/libavformat/hls.c index 01731bd36b..0995345bbf 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -205,6 +205,7 @@ typedef struct HLSContext { AVDictionary *avio_opts; int strict_std_compliance; char *allowed_extensions; + int max_reload; } HLSContext; static int read_chomp_line(AVIOContext *s, char *buf, int maxlen) @@ -1263,6 +1264,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 +1296,9 @@ restart: reload_interval = default_reload_interval(v); reload: + reload_count++; + if (reload_count > c->max_reload) + 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) { @@ -2150,6 +2155,8 @@ static const AVOption hls_options[] = { OFFSET(allowed_extensions), AV_OPT_TYPE_STRING, {.str = "3gp,aac,avi,flac,mkv,m3u8,m4a,m4s,m4v,mpg,mov,mp2,mp3,mp4,mpeg,mpegts,ogg,ogv,oga,ts,vob,wav"}, INT_MIN, INT_MAX, FLAGS}, + {"max_reload", "Maximum number of times a insufficient list is attempted to be reloaded", + OFFSET(max_reload), AV_OPT_TYPE_INT, {.i64 = 1000}, 0, INT_MAX, FLAGS}, {NULL} };