From patchwork Wed Oct 4 22:03:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 5414 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.76 with SMTP id m12csp1347278jah; Wed, 4 Oct 2017 15:09:04 -0700 (PDT) X-Received: by 10.223.128.236 with SMTP id 99mr17670036wrl.138.1507154944248; Wed, 04 Oct 2017 15:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507154944; cv=none; d=google.com; s=arc-20160816; b=M8e5lW/Mp5210sAcc4SciSS73IKS/D2TWt0KXuf07MsBRwFajOiLXy/M7samVw6rgK a63YsSsl4JxlxqjQKUrjGEY8IJ7RuZpRyoh8BJso0ysLfyDgP3xNpxDjchEupzUXYNXs hkqBvG6OpGb0CiLVlUtgR/q5eG6F00Wlv0LcbN0ggk1Y41jBqCd6aE/yZViythcMr8Gh bK0kKOCDDLmuOIj1Izh6UG9JCt87U9L1haU7dxE5AOB+X0WCTXaw9E/9QUCzGBes3jfP Y7hlF6HvwzEHTv4d7IUdMN2/Pnjzvmc1FSk5jZE4xo0dVEpJ3uDWiOSPI912ac4S30+6 U6IA== 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=xFwStLAewRaOMCgOhYlrxpUgnMYyHTchpd/teYvdUAE=; b=M3x8sns68pqUgErsEnVtU4AJaigcNdgDtYLy8gQZg995ICEnDZwGX4e1DaNXtBnGQ9 F7Iw2vuNYktoMhLYtgXNEhvDzXtDHUL4A9ws8tchowFDnoenVMToY+9Rzo0xDHdkEwGW /scqfNugXOose1nYUQtg8Ou9SyNR8pBXxuQ0/k4Qdy+4Ixo5exfRLpmCbVgvdPFTBm9G XCzBaXphXRRDX/6Dt0QTnxZA/Jd/XX33IWT9ROAsPWXf5wWS4c1St5L+p0Fko/fj4f/e x44E4DyPGWFv+EJ0WegN2hB3EEb0WJkRpUMWPtVU/Y97nnW3UP1WmJb26k6DGBTMue34 ibfQ== 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=y6soIPki; 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 59si14166576wrs.177.2017.10.04.15.09.03; Wed, 04 Oct 2017 15:09:04 -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=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=y6soIPki; 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 6F44968A381; Thu, 5 Oct 2017 01:08:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B786968A342 for ; Thu, 5 Oct 2017 01:08:40 +0300 (EEST) Received: by mail-pf0-f196.google.com with SMTP id e69so13295634pfg.4 for ; Wed, 04 Oct 2017 15:08:56 -0700 (PDT) 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=+lrq64YMtgq27a/FZxFSTzbmX4C2nc1S/wSwW3q+GfE=; b=y6soIPkiXWZKo48xwk5VUx6nzLJGqbYgoqZ/H5tRwYV4wbo+G1hfSDELiRuan8jlFm Pbh3Ph20UGH/eYsJ5gWpePMuuGmWVjEcwH5nuI4H56bN0FGKp0dj5JfJifl6EjrULL5a mnEQ6m+Yp6e8HWjHZAkUmS+oP3m1Pme60q6HulchnBCvcv4WDYCONlZtAsR/ZclhaP8i Pb0LiX2kMVL8IIzZlpQv/p7hoAkiEBoQ9t+TIgXaQgkj4am5Uugrje22AqwXJzA/eVGv GEetT20T7z+daqTkiRnZHWatInAqPslQJDhnZuu/TJFwygqJgb0ZE275nRS70WcHpmvn 31jw== 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=+lrq64YMtgq27a/FZxFSTzbmX4C2nc1S/wSwW3q+GfE=; b=FGQPBUCJaqd5oWO+GnFxguq4FphzLGH8duUuvZFG7Nd2vujLgjsKdALhyU4vXugIXu pCDUu6NSQrg5VkMSlIG61/QZASL/WGw2cX4wavP+l82PZEnmKOfKJ3jqbu8dUmFvWz+Z KE5lLE6ewz7vzMNqUN/tW0yVu7aPdkOVisqSdj3tiKi1566YUgUIOoowMu7Q9WU1anHq qqmG79PlflbrqAwqS5HOAtzncyXg7V9Av83oBlpb8ivd4q7LeWNspcqmIi4z8I5mI+Pc 4Gfk4NDKt/vqpXq5fQ/4F1QDa+FfxXC+d7M4kc4vlXVmGeJXENJmAyo8yWmEtLCv916y zb9g== X-Gm-Message-State: AHPjjUhS1i0nwPA8pqvIYgscuDp7iT88JOX7AEJVSk+sNajqu8ePkmmm 7yRpIJEYsFwAkc2WKxrgpVoxH0L1 X-Google-Smtp-Source: AOwi7QDH1aoAIc9KRTrslZ0Uz32jHNNyIHMy4urCeXD9MOEY+ofa4blt46e++B5ck6i+CnbOCAXkyg== X-Received: by 10.84.191.228 with SMTP id a91mr20398146pld.81.1507154618398; Wed, 04 Oct 2017 15:03:38 -0700 (PDT) Received: from tmm1-macbook.local.net (c-73-252-174-83.hsd1.ca.comcast.net. [73.252.174.83]) by smtp.gmail.com with ESMTPSA id u20sm26404120pfh.171.2017.10.04.15.03.37 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 04 Oct 2017 15:03:37 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Oct 2017 15:03:32 -0700 Message-Id: <20171004220334.79264-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.13.5 (Apple Git-94) Subject: [FFmpeg-devel] [PATCH 1/3] 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: 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. This bheavior is reset in ff_http_do_new_request(), which is used to make additional requests on the open socket. --- libavformat/http.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libavformat/http.c b/libavformat/http.c index 668cd51986..6af3259a43 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 0; + } if (!s->chunksize) { char line[32]; int err; @@ -1296,8 +1301,11 @@ 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) { + http_get_line(s, line, sizeof(line)); // read empty chunk + s->chunkend = 1; return 0; + } else if (s->chunksize == UINT64_MAX) { av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n", s->chunksize);