Folks

We've discovered an interesting bug in Channel.getInputStream() (and
potentially also in Channel.getOutputStream()) which can lead to receiving
truncated messages depending on how calling code uses JSch

The basic problem is that each call to Channel.getInputStream() creates a
completely new instance of an InputStream with its own private buffering.
Therefore if you call getInputStream() multiple times (because for example
you passed a Channel object between several methods each of which needs to
access the InputStream) there is a chance that the later call will get an
InputStream that misses some/all of the expected data because it was already
received and buffered in the previous InputStream you obtained.

This seems like a rather odd and buggy behaviour, I would suggest that the
code be changed such that once an InputStream has been created for a Channel
the same instance is always returned.  Right now we've had to work around
this by ensuring we only call getInputStream() once and then passing around
the InputStream instance in addition to the Channel instance.

A similar problem seems to apply to Channel.getOutputStream() though this is
less likely to be encountered provided that you remember to always call
flush() on the OutputStream when you've done writing to it.

Thanks,

Rob





------------------------------------------------------------------------------
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to