From patchwork Wed Oct 25 18:14:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 5690 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp2138452jah; Wed, 25 Oct 2017 11:41:53 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Raa0fNIeXn8ixn+H0AT9bnqk1a3T2uwQTssWOy6ynTjQRsH/ZHaxLyf/w2acDZxk/GVCyS X-Received: by 10.223.134.212 with SMTP id 20mr2961415wry.81.1508956913600; Wed, 25 Oct 2017 11:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508956913; cv=none; d=google.com; s=arc-20160816; b=qREKGjw42zeEN0zbcuLwppuKrZKlpa9BNxBTwGwt52DxjGqPBQe9O+vYkDDNnnoOu5 9kIV0tuTwUGdmw5wQ+7hglOwUK7hFimq3rJTgPqhv4uo1/uJaJitPNjxzN/1Eu4aIwkm 5ZqrJKgF+g+8gZXWmNK0VYCj0c0p6q7ZjZxHxPJhvcU1B1JOZuv/ENCgFAlH6tRw3kCb sKStddbFkMGqWPCf4LcP3ZAum1UsPswFA8kTUy/7KKPHLfyr3dRRC3jWsRGBoUB5tJG0 16Oz3Xb0xT+4vg2bKwnX3xw6i9WmW2nlzslYubQIHgG2tK+35lD3f5uVCQDx0/T+xloG N8Qw== 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=PAHYhaWNpg/Gc/TuaN91rDLHBsGgapJ1u8VD3gYPvBM=; b=jg1JiltvGh9gRc1THZoz1FdnzNVXDizm+x0fXY0qrgiKRnw5b9f0C87JG9kz+lWhjZ viq3kHCcojVb6bs4jGae+fnohocomDxqx7zRbcBsJ20CC6bd5GgHEYptdhDQXzKyUiNB mJajPKE+o+aAV5VEPNb1CWW8so/Bp5MTG3ecCk4z2hpJU5wtPU7CeeGEvL44PGMg9F4G B9w0kWhGt/Ywx457+mVd587l6JCqtCvnrE9Vgz16ouEOms6bBL7Bo63sp8bRIXPxLVSs 43ZatVqQS3Z8sWrxRuVUi9SZ9lU2GThbgzXxJ/PwxBigdkNEH0tfKTrMOW2yytevjzcL yxQQ== 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=sdhcRrXD; 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 200si343193wml.132.2017.10.25.11.41.52; Wed, 25 Oct 2017 11:41:53 -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=sdhcRrXD; 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 3297D68A49A; Wed, 25 Oct 2017 21:41:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D77868A430 for ; Wed, 25 Oct 2017 21:41:38 +0300 (EEST) Received: by mail-pg0-f65.google.com with SMTP id l24so656407pgu.11 for ; Wed, 25 Oct 2017 11:41:45 -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=RraZv5brEHCuDLk84rI0cITqrl65dIfuO4x0uRp/Q2c=; b=sdhcRrXD3lMoRjB60wce9rijMnkqC6jExnC0O63P65zjhcJi3Kwc2u4fampAyFH0yb /XcFv1pWAGf4dWnQBW6kBtesiIgoSbZzkip4G5FVKigVyAWXoM3PgM+y4uYpPGk23Q7v SIuPGSiWJPhfNnemdNa9lmoF5GIhei7pXGZ0V7Q2XiPtx3iStPkfirgDXx1kXz/f2AEH H3AVMR4JUUx713oI3tlkZF3qqEaJ+lc/hob/2uE/Ta6BerwosIfkU/iacxf0aqZmYHGw qeg1vQ3ZLE8LPoFDpVGOwHPZ7Q6OttAxl31Pev9qobpomB3JtwnTTfiJ0l6dUhj58jlX 9+Tw== 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=RraZv5brEHCuDLk84rI0cITqrl65dIfuO4x0uRp/Q2c=; b=ZqFA5vXgkIc2Szy9SyUSWhRUCX96Pnx2VzwmAXPKHMENf0seFJCxjxWgU1QxaPuRIb DQ7lEkKkdxJpHyzoHk8LQ2n7rk7NwS6HsABWwfUjfaVh4h1CUb3joCTP+dehAo8BXEXc byaFTAYVpIyzLPUmfPLURjtbG0+EjEDmheWvVnOvQMFCRoxJxCeD/63wR/VJWePu0Cz+ 3/G0/flIthCpLRzeTfGuosyLlNflKb2/MPVgszHinfxfkmHhRRnQy/zEFRp4xTxuis/c 6oKECa9VHtpnodisgc0HluiUbqbfbk77mqyhobyCBc35FRN6ZderAvlA6OQbymMsCygg LYoA== X-Gm-Message-State: AMCzsaUXfa3S3NP95YNbaYB5UQpnGOCAenOcvis+mWwgKJW2qYfS8SW8 ILyNUqKmjnjeot6+VkK0ygk1uT4W X-Received: by 10.98.34.131 with SMTP id p3mr2946400pfj.1.1508955315087; Wed, 25 Oct 2017 11:15:15 -0700 (PDT) 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 i129sm5918698pgd.21.2017.10.25.11.15.14 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Oct 2017 11:15:14 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Wed, 25 Oct 2017 11:14:59 -0700 Message-Id: <20171025181500.6261-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.14.2 Subject: [FFmpeg-devel] [PATCH 1/2] lavf/tls_securetransport: return buffered data first from tls_read 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 This fixes a deadlock while reading a chunked https response, if multiple_requests=1 is also set. Without an EOF to signal the end of the last chunk, tls_read gets stuck forever trying to read more data than is available. This occurs with the http protocol reproducibly, because http.c always reads 4kb at a time, and the last chunk of an http response is often much smaller. After this commit, tls_read always returns any buffered plaintext first before attempting to read more encrypted data off the underlying tcp socket. --- libavformat/tls_securetransport.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavformat/tls_securetransport.c b/libavformat/tls_securetransport.c index bc8a32069e..9ea588ae3a 100644 --- a/libavformat/tls_securetransport.c +++ b/libavformat/tls_securetransport.c @@ -352,8 +352,12 @@ static int map_ssl_error(OSStatus status, size_t processed) static int tls_read(URLContext *h, uint8_t *buf, int size) { TLSContext *c = h->priv_data; - size_t processed = 0; - int ret = SSLRead(c->ssl_context, buf, size, &processed); + size_t available = 0, processed = 0; + int ret; + SSLGetBufferedReadSize(c->ssl_context, &available); + if (available) + size = FFMIN(available, size); + ret = SSLRead(c->ssl_context, buf, size, &processed); ret = map_ssl_error(ret, processed); if (ret > 0) return ret;