]> git.sesse.net Git - ffmpeg/commitdiff
This fixes a deadlock while reading a chunked https response, if
authorAman Gupta <aman at tmm1.net>
Mon, 13 Nov 2017 21:02:44 +0000 (15:02 -0600)
committerRodger Combs <rodger.combs@gmail.com>
Mon, 13 Nov 2017 21:04:55 +0000 (15:04 -0600)
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.

Signed-off-by: Rodger Combs <rodger.combs@gmail.com>
libavformat/tls_securetransport.c

index dc32eb1fa898d9e2de70d491ae4aadf550c22b57..37380541b11c9d9c0b1c1018eb9d1f1ea3202636 100644 (file)
@@ -364,8 +364,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;
 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;
     ret = map_ssl_error(ret, processed);
     if (ret > 0)
         return ret;