Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SftpInputStreamAsync#read(byte[], int, int) fails on calls with len = 0 #398

Closed
mkeckmkeck opened this issue Jul 19, 2023 · 0 comments · Fixed by #399
Closed

SftpInputStreamAsync#read(byte[], int, int) fails on calls with len = 0 #398

mkeckmkeck opened this issue Jul 19, 2023 · 0 comments · Fixed by #399
Assignees
Labels
bug An issue describing a bug in the code
Milestone

Comments

@mkeckmkeck
Copy link

mkeckmkeck commented Jul 19, 2023

Version

2.9.2

Bug description

When passing len = 0 on a second read call, after eofIndicator has already be set to true, the read method returns -1. This can lead to an incomplete read when using e.g. java.io.InputStream#readAllBytes or java.io.InputStream#readNBytes(int).

A possible solution would be an early return of 0 in case of len = 0

Actual behavior

First reading offset 0, len 8192,
then offset 8192, len 0
then offset 8192, len 8192

Return in sum at most 8192 bytes (if available)

Expected behavior

First reading offset 0, len 8192,
then offset 8192, len 0
then offset 8192, len 8192

Return in sum more 8192 bytes (if available)

Relevant log output

No response

Other information

No response

mkeckmkeck added a commit to scireum/sirius-biz that referenced this issue Jul 19, 2023
- org.apache.sshd.sftp.client.impl.SftpInputStreamAsync#read(byte[], int, int) sometimes
  behaves incorrectly when reading a length of 0 by returning -1 whilst the actual buffer does
  not hit EOF yet
- see apache/mina-sshd#398 for details
- the BufferedInputStream is a workaround, as it early returns 0 when requesting length 0
@tomaswolf tomaswolf added the bug An issue describing a bug in the code label Jul 20, 2023
@tomaswolf tomaswolf added this to the 2.10.1 milestone Jul 20, 2023
@tomaswolf tomaswolf self-assigned this Jul 20, 2023
tomaswolf added a commit to tomaswolf/mina-sshd that referenced this issue Jul 20, 2023
Only return EOF once the EOF indicator is set *and* there is no more
buffered data.

Bug: apache#398
tomaswolf added a commit that referenced this issue Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue describing a bug in the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants