Subject: Re: error checking question

Re: error checking question

From: Peter Stuge <>
Date: Fri, 22 Jul 2011 19:28:39 +0200

Mark Roden wrote:
> Out of a set of 65 files, maybe 1 will be corrupted like this, but
> it's only happening 1 in 500 or so files.

Interesting issue. It should not be hard to fix once identified

> Is there any chance that libssh2 could be responsible for this issue?

Sure, there can be a bug in libssh2 causing this.

> Is there a verbose checking mode, or is checking for transfer
> success automatically done?

As Daniel mentioned, the SSH protocol includes message authentication
for every SSH packet sent, and TCP includes checksumming to make sure
that SSH packets cross the net well.

So the corruption will neccessarily come either from the sending or
the receiving process, assuming that the two filesystems (on sender
and receiver side) are not the cause.

First find out exactly where and how the file has been corrupted;
which offset does the corruption start at and can a pattern for the
corruption be identified. (Some bit consistently wrong, are bytes
missing or are there extra bytes moving the correct data forward or
backward etc. etc.)

In particular collect the above information for several failed runs,
to determine if the problem has some consistent parameters. Ie.
always at the same offset in the file, or always after sending the
same total amount of bytes, or some other pattern.

Then compile a libssh2 with debug messages enabled, and add to your

libssh2_trace(session, LIBSSH2_TRACE_TRANS);

which provides clear text data for packets sent and received. You can
then match the data that is received with the data that libssh2
writes into the buffers that you provide for receiving data.

Note that libssh2 return values work slightly differently from e.g.
read() because libssh2 does not return the packet size until the full
packet has actually been transferred. It could help to also add
buffer debugging into your application, to verify that you see the
exact same data that libssh2 sees. I'm attaching a function I use for
this. Just #include "xxd.c" in file scope and then call xxd(buffer,length);

I'd love to hear more details about this problem. If you've discovered
a problem in libssh2 I think it's important that we fix it. Thanks!



Received on 2011-07-22