From 10b66cef0845a60b85f2621bfc38303d23ce0dc5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 8 Sep 2011 22:47:38 +0200 Subject: [PATCH] sftp_read: cap the read ahead maximum amount Now we only go up to LIBSSH2_CHANNEL_WINDOW_DEFAULT*30 bytes SFTP read ahead, which currently equals 64K*30 == 1966080 bytes. --- src/sftp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sftp.c b/src/sftp.c index b5400193..d005e309 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1110,10 +1110,14 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, /* We allow a number of bytes being requested at any given time without having been acked - until we reach EOF. */ if(!filep->eof) { + size_t max_read_ahead = buffer_size*4; + if(max_read_ahead > LIBSSH2_CHANNEL_WINDOW_DEFAULT*30) + max_read_ahead = LIBSSH2_CHANNEL_WINDOW_DEFAULT*30; + /* if the buffer_size passed in now is smaller than what has already been sent, we risk getting count become a very large number */ - if((buffer_size*4) > already) - count = (buffer_size*4) - already; + if(max_read_ahead > already) + count = max_read_ahead - already; /* 'count' is how much more data to ask for, and 'already' is how much data that already has been asked for but not yet returned. So, if