From 900c90ccbe9a36b2e90a78647568368ed333b517 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 26 Aug 2011 11:45:48 +0200 Subject: [PATCH] sftp_read: advance offset correctly for buffered copies In the case where a read packet has been received from the server, but the entire contents couldn't be copied to the user-buffer, the data is instead buffered and copied to the user's buffer in the next invocation of sftp_read(). When that "extra" copy is made, the 'offset' pointer was not advanced accordingly. The biggest impact of this flaw was that the 'already' variable at the top of the function that figures out how much data "ahead" that has already been asked for would slowly go more and more out of sync, which could lead to the file not being read all the way to the end. This problem was most noticable in cases where the application would only try to read the exact file size amount, like curl does. In the examples libssh2 provides the sftp read function is most often called with a fixed size large buffer and then the bug would not appear as easily. This bug was introduced in the SFTP rewrite in 1.2.8. Bug: http://curl.haxx.se/mail/lib-2011-08/0305.html http://www.libssh2.org/mail/libssh2-devel-archive-2011-08/0085.shtml --- src/sftp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sftp.c b/src/sftp.c index 0acccd0..76ffaaf 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1098,6 +1098,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, total_read += copy; filep->data_left -= copy; + filep->offset += copy; if(filep->data_left) return total_read;