[
https://issues.apache.org/jira/browse/SSHD-1348?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18044764#comment-18044764
]
Thomas Wolf commented on SSHD-1348:
-----------------------------------
Q1: don't know. In SftpSubsystem, this was changed in 2015 in commit
f60fb919c4, probably unintentionally. AbstractSftpSubsystemHelper was
introduced in 2017 with >=.
Q2: yes, sending an SSH_FXP_READ with a zero length is valid and should work.
However: it's a bit unclear what should happen if the zero read is at the end
of the file. Should this return SSH_FXP_STATUS with SSH_FX_EOF, or should it
return SSH_FXP_DATA with zero bytes? Probably the former, but that's not what
SeekableByteChannel does, and so it would have to be implemented explicitly,
probably in FileHandle.read() returning -1 if length == 0 && offset >=
channel.size(). A zero read anywhere before the end of the file is no problem,
it'll just return a zero-byte SSH_FXP_DATA.
> Client SSH_FXP_READ() with lenght = 0 causes SSH_FX_INVALID_PARAMETER into
> Apache SSHD SFTP Server
> --------------------------------------------------------------------------------------------------
>
> Key: SSHD-1348
> URL: https://issues.apache.org/jira/browse/SSHD-1348
> Project: MINA SSHD
> Issue Type: Question
> Affects Versions: 2.16.0
> Reporter: Roberto Deandrea
> Priority: Major
> Attachments: sftp-read-empty.py
>
>
> During SFTP client get of empty file setting lenght=0 , Apache SSHD replies
> with SSH_FXP_STATUS with SSH_FX_INVALID_PARAMETER.
> We have noticed 2 different checks on buffer lenght.
> In method SftpSubsystem.doRead() the check on length is the following:
> *{color:#242424}ValidateUtils.checkTrue((long)length > 0L, "Invalid read
> length: %d", (long)length);{color}*
> In method {color:#242424}AbstractSftpSubsystemHelper{color}.doRead() the
> check on length is the following :
> *{color:#242424}ValidateUtils.checkTrue(readLen >= 0, "Illegal requested read
> length: %d", (long)readLen);{color}*
>
> Q1. Is there a reason why the check on length are different ?
> Q2. Is possble to read a file setting buffer lenght = 0 ?
>
> Thank you for your cooperation.
> Roberto Deandrea
>
> P.S. Attached to this Jira you can find a python script to simply reproduce
> this issue.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]