sshnet / sshnet/SSH.NET

FileStream ReadAsync method fails with invalid argument for Golang server

Open
#1,616 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

I am from the Azure Logic apps team. One of our users have a custom SFTP server implemented in Golang and when we try to read a file we get the following error:

Renci.SshNet.Common.SshException: invalid argument
   at Renci.SshNet.Sftp.SftpSession.RequestRead(Byte[] handle, UInt64 offset, UInt32 length)
   at Renci.SshNet.Sftp.SftpFileStream.Read(Byte[] buffer, Int32 offset, Int32 count)

Our code looks like this. We are using 2024.1.0 version

 using (var sftpClient = new SftpClient(host, port, username, password))
 {
     sftpClient.Connect();

     if (sftpClient.IsConnected)
     {
        var fileMetadata = sftpClient.GetAttributes(filePath);
        var buffer = new byte[fileMetadata.Size];
        using (var fileStream = sftpClient.Open(path: filePath, mode: FileMode.Open, access: FileAccess.Read))
       {
            await fileStream.ReadAsync(buffer, 0, buffer.Length);
       }
     }
     else
     {
         Console.WriteLine("Failed to connect to the SFTP server.");
     }

     // Disconnect
     sftpClient.Disconnect();
 }

On checking the server traces we see this error there runtime error: invalid memory address or nil pointer dereference.

Any idea what could be causing this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SftpFileStream.ReadAsync and the SftpSession.RequestRead stack frames, using the reported 2024.1.0 behavior and the supplied ReadAsync example as the reproduction. Compare the client request with the Golang SFTP server trace showing a nil pointer dereference; done means identifying whether the incompatibility is in SSH.NET or the server and documenting a reproducible root cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.