Subject: LIBSSH2_SFTP_PACKET_MAXLEN

LIBSSH2_SFTP_PACKET_MAXLEN

From: Michael Harris <michael.harris_at_ericsson.com>
Date: Fri, 11 Nov 2011 14:57:41 +0800

Hi,

We have struck a problem with reading directories using libssh2_sftp_readdir where the remote directory contains a lot of long filenames.

The directory concerned has 394 files in it, each with a filename length of 154 characters. After reading the first SFTP packet worth of names, it hangs and we see the following debug message:

[libssh2] 1.741003 Failure Event: -25 - SFTP packet too large

When I add up the size of all the transport packets, the total comes to 40240 bytes. But in include/libssh2_sftp.h I see

#define LIBSSH2_SFTP_PACKET_MAXLEN 40000

Sure enough, if I rebuild libssh2 with the above constant set to, eg, 60000 then it works perfectly.

In the RFC it says:

   The maximum size of a packet is in practice determined by the client
   (the maximum size of read or write requests that it sends, plus a few
   bytes of packet overhead). All servers SHOULD support packets of at
   least 34000 bytes (where the packet size refers to the full length,
   including the header above). This should allow for reads and writes
   of at most 32768 bytes.

but in the case of SSH_FXP_READDIR packets I can't see how the server would know the maximum length.

Of course I can build a patched version of libssh2 with this change, but the question is - is there a more valid way to determine the maximum size? Or is there some way we should be telling the server the maximum SFTP packet size we are willing to accept?

The server is openssh 4.3p. The fault has been reproduced with both Linux and Solaris servers. It is enough to create a directory and touch 394 files each with names of 154 characters in length.

Regards // Mike

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-11-11