From patchwork Mon Nov 13 20:31:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 6032 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp2522689jah; Mon, 13 Nov 2017 12:31:26 -0800 (PST) X-Google-Smtp-Source: AGs4zMZhyQZDDTyOnPjtM3CLzJZOH82+59xsVTIinp+zdXSoGNsu4/4950xAtl2XETRP74GEB3pD X-Received: by 10.223.198.18 with SMTP id n18mr7707804wrg.96.1510605085932; Mon, 13 Nov 2017 12:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510605085; cv=none; d=google.com; s=arc-20160816; b=tWEUb4/FO/plMiXUectSQTmzOfwBvHB9YXrEStG/GfhImR5lgxl6BHg6cIKSUOW6eU mwBPQ+KC2rOPJHaiu8aMS13DxDUjPDCsAq/Z01pdWZDAeOmRgc3TVKeco/QzhPDjSVDA 6QtVvqEwhPB8w4jD1o4lJwxZd6et5j1VyZZOhHKligr1nsyHlXg3+BQqeVA9Xx94Oqey /58Xeju6Jx0O+40/4oeZLvdAgGXMRATIRG6g53sBqrztyYpXNsWEJkwSdyfZvjNjXTw1 34+wfyHFFzD+Z/NHb85t0ns4RoqUQh1/7v/dLw3WrZNTL+SMMK1nAhuU5AcYWhQ2ciTW A8Rg== 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:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=Tw4BrrCzyfUa0ZvR1eR2IAt8wkZVXglbKUMmHTEuBhQ=; b=FTqF9kDY9PAsNIUTlfYfADs5eqOU1KzzCdXyojIMgT/RjNJE0bt1fuS3OntuK6ifQl /uZMlIvi3gIeChzvLnCaMzs6S2DllXrBScfjoDiv1vmD0VBVTGJfs8+ICxGmhLBUdOHu rEaOG6KVmYvUlk7ZwxcGSp+ijqEA8so4F0oc9bbBaMki9fOdy8pceGiQb4ZXupZnIwHh l6zOaAatT3guE00VxKa/CVwSOKVCG3zDKGxumToSdHIJ3nAqKKSMB5qHdmweXIcvxxKU tbWTjDis1YXCHbRAzXwAeos4FwcG/pGJyG16iNx8ukyt4QLde0G2npffIQNXTh0EfU56 saxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=oPN1LI7W; 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 d9si14074754wrh.118.2017.11.13.12.31.25; Mon, 13 Nov 2017 12:31:25 -0800 (PST) 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=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=oPN1LI7W; 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 CE6FB68A4F0; Mon, 13 Nov 2017 22:31:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f173.google.com (mail-pf0-f173.google.com [209.85.192.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DAE3568A402 for ; Mon, 13 Nov 2017 22:31:03 +0200 (EET) Received: by mail-pf0-f173.google.com with SMTP id n89so12652106pfk.11 for ; Mon, 13 Nov 2017 12:31:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=2+shCms6XllhIr2m04poZzWa3qXnJJFwTtfmoMxirbQ=; b=oPN1LI7W0hRjXhWAqcUJM6Bx7EIJatLaE4r/sE5u+e08W8SudjiPqSlTxhPiVSiUwX Zt3Xnu8H4PNLdKW2n01M4zBXODzEMIA9tcZdVQWRuMPk2ZV+09L/9RCOdVfLjfHKMSRY LMa/MjYYmuYQe1Wj3AKaLIECDtMxvirZt/BJ9PrbaDrdPFB5piUOzMNmLfCYm7iDO/f0 n6i0W3lbRV/gjL14V/G+ZDQ57yk4dYpypQx+amVjiD6MQFsyJ8SnArDCb75DebNICeLR EiETRggmGqR+A43G818PPqqyBkMHrhjOLNHjkc7GaObg0JA6xciLHomOL3J4vsczIkYg k1vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=2+shCms6XllhIr2m04poZzWa3qXnJJFwTtfmoMxirbQ=; b=KNkxSK3oMvpAqvln2gD3hKaG/7AHJOZ8k6nAf0chKquS5yC2b+9qPo//7KuFgMZq+y 1b9BJRJRQ3zB8DGWtn/hVu+aKaFUObLeflSU7J7mzrR/3kKNAt9qo90DW9346aAnzLYl 6mRD+gDZn+YCef/oZGpdofDnGqQFtKCTzOyDOJhcBWthpHDHYWu4R5dGUSZB8XsvCgtM Buolj6z3Jc1IGPiUwY0ROg6FXfswaKV0rQFeA+F2j8xamoTCEbr9uurgRF9B/hNKtEyN efqYmvimPSgUJnPXKnXcaXJ7lX8bITUywney+HXRb/uA+HaySOxaCAGQYcDlrWRxpcTH VMjA== X-Gm-Message-State: AJaThX6hC7HGYPCpvQHVQyq6K79cDMNPdGLtp5Tn02wbHJy6fu1mWZng 2951j+DMAdLCQH2i7K2en62WMc7E X-Received: by 10.101.87.193 with SMTP id q1mr9900865pgr.370.1510605076553; Mon, 13 Nov 2017 12:31:16 -0800 (PST) Received: from tmm1-imac.local.net (c-73-252-174-83.hsd1.ca.comcast.net. [73.252.174.83]) by smtp.gmail.com with ESMTPSA id p12sm26215624pgn.60.2017.11.13.12.31.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Nov 2017 12:31:15 -0800 (PST) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Nov 2017 12:31:08 -0800 Message-Id: <20171113203108.25467-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.14.2 Subject: [FFmpeg-devel] [PATCH] avformat/http: fix chunked response w/ multiple_requests=1 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: rsbultje@gmail.com, Aman Gupta MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta Currently if you use the multiple_requests=1 option and try to receive a chunked-encoded response, http_buf_read() will hang forever. After this patch, EOF is emulated once a 0-byte final chunk is received by setting a new flag. This flag is reset in ff_http_do_new_request(), which is used to make additional requests on the open socket. --- libavformat/http.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libavformat/http.c b/libavformat/http.c index 29635eb546..056d5f6583 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -66,6 +66,7 @@ typedef struct HTTPContext { int http_code; /* Used if "Transfer-Encoding: chunked" otherwise -1. */ uint64_t chunksize; + int chunkend; uint64_t off, end_off, filesize; char *location; HTTPAuthState auth_state; @@ -305,6 +306,7 @@ int ff_http_do_new_request(URLContext *h, const char *uri) AVDictionary *options = NULL; int ret; + s->chunkend = 0; s->off = 0; s->icy_data_read = 0; av_free(s->location); @@ -1281,6 +1283,9 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size) int len; if (s->chunksize != UINT64_MAX) { + if (s->chunkend) { + return AVERROR_EOF; + } if (!s->chunksize) { char line[32]; int err; @@ -1296,7 +1301,12 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size) "Chunked encoding data size: %"PRIu64"\n", s->chunksize); - if (!s->chunksize) { + if (!s->chunksize && s->multiple_requests) { + http_get_line(s, line, sizeof(line)); // read empty chunk + s->chunkend = 1; + return 0; + } + else if (!s->chunksize) { av_log(h, AV_LOG_DEBUG, "Last chunk received, closing conn\n"); ffurl_closep(&s->hd); return 0;