hogehoge-co-jp / ganymed-ssh-2

Automatically exported from code.google.com/p/ganymed-ssh-2
Other
0 stars 0 forks source link

SCPInputStream.read() miscounts remaining bytes #39

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The SCPInputStream class keeps track of the number of remaining bytes. In 
method read() (the one without arguments), the line

  remaining -= read;

should really be

  remaining--;

In most cases, this causes files read using SCPInputStream's read() method to 
end prematurely.

Original issue reported on code.google.com by jonas.es...@googlemail.com on 11 Mar 2014 at 2:39

GoogleCodeExporter commented 9 years ago
I don't understand why this is incorrect.

Original comment by dkocher@sudo.ch on 8 Apr 2014 at 11:44

GoogleCodeExporter commented 9 years ago

Original comment by dkocher@sudo.ch on 9 Apr 2014 at 1:12

GoogleCodeExporter commented 9 years ago
Sorry if I didn't clarify enough.

The bug is subtle and difficult to recognize with the eye, given that the exact 
same sequence of lines is correct in line 112 in the other read(...) method 
(the one with signature read(byte[], int, int)).

But, in the read() method without arguments, the value returned by the call to 
super.read() (in line 81, [1]) is _not_ the _number_ of bytes read, but the 
_value_ of the last read byte, as per definition of read (see [2]). It is thus 
an error to subtract that value from the number of remaining bytes, since the 
number of remaing bytes has only decreased by 1 (at max).

At the company I work for we use a workaround for this bug (only use the 
read(byte[]) variant).

Hope I made it clearer this time.

[1] 
https://code.google.com/p/ganymed-ssh-2/source/browse/trunk/src/main/java/ch/eth
z/ssh2/SCPInputStream.java#81
[2] http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read()

Original comment by jonas.es...@googlemail.com on 10 Apr 2014 at 8:56

GoogleCodeExporter commented 9 years ago
Thanks for the clarification. Fix in r103.

Original comment by dkocher@sudo.ch on 10 Apr 2014 at 1:58