Bugs item #1908724, was opened at 2008-03-06 12:41 Message generated for change (Comment added) made by mikeprotts You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1908724&group_id=125852
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: SFTP Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Mike Protts (mikeprotts) Assigned to: Daniel Stenberg (bagder) Summary: sftp 4GB stat problem Initial Comment: I have been working with libssh2 and curl and found a problem with the stat of a remote file that is larger than 4GB (curl uses this to decide when the transfer has finished). The attr size value returned from libssh2_sftp_stat is losing the hig bytes, therefore returning a size - 4GB instead of size. The problem seems to be in misc.c function libssh2_ntohu64 where the return value is being calculated, and I think the compiler is performing calculations as 32 it instead of 64. I have a work around (below) which seems ok - comments welcome. libssh2_uint64_t libssh2_ntohu64(const unsigned char *buf) { unsigned long lsl, msl; libssh2_uint64_t aval64; /* Used for return value */ msl = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; lsl = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; aval64 = msl; /* No cast needed as 32 to 64 bit should work */ aval64 = aval64 * 65536 * 65536; /* now force to correct value */ aval64 = aval64 + lsl; /* add 32 to 64 bit should be ok */ return aval64; /*was ((msl * 65536) * 65536) + lsl;*/ } In case this is thought to be a compiler issue, the compiler information +follows: [EMAIL PROTECTED]:~/src/rexxcurl/RexxCURL-2.0$ uname -a Linux rockwell 2.6.18-5-686 #1 SMP Wed Sep 26 17:54:59 UTC 2007 i686 GNU/Linux [EMAIL PROTECTED]:~/src/rexxcurl/RexxCURL-2.0$ gcc -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v +--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr +--enable-shared --with-system-zlib --libexecdir=/usr/lib +--without-included-gettext --enable-threads=posix --enable-nls +--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu +--enable-libstdcxx-debug --enable-mpfr --with-tune=i686 +--enable-checking=release i486-linux-gnu Thread model: posix gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) -- Regards Mike Protts Senior Technical Consultant Pro:Atria Ltd +44(0) 870 7656453 [EMAIL PROTECTED] ---------------------------------------------------------------------- >Comment By: Mike Protts (mikeprotts) Date: 2008-03-06 12:59 Message: Logged In: YES user_id=1341507 Originator: YES I'll try both and report back. Cheers Mike ---------------------------------------------------------------------- Comment By: Daniel Stenberg (bagder) Date: 2008-03-06 12:52 Message: Logged In: YES user_id=1110 Originator: NO The problem is that the calculation is done with only 32bit values, so at least one of them need to be typecasted to a 64bit version. How about this patch (much smaller): --- misc.c 6 Aug 2007 20:48:06 -0000 1.19 +++ misc.c 6 Mar 2008 12:50:09 -0000 @@ -62,7 +62,7 @@ msl = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; lsl = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; - return ((msl * 65536) * 65536) + lsl; + return (((libssh2_uint64_t)msl * 65536) * 65536) + lsl; } Although I would prefer to clean this up while at it, and intead do the following patch - would be cool if you could verify if this works fine too: --- misc.c 6 Aug 2007 20:48:06 -0000 1.19 +++ misc.c 6 Mar 2008 12:51:44 -0000 @@ -62,7 +62,7 @@ msl = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; lsl = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; - return ((msl * 65536) * 65536) + lsl; + return (((libssh2_uint64_t)msl <<32) | lsl; } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1908724&group_id=125852 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ libssh2-devel mailing list libssh2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libssh2-devel