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

FileStream ReadAsync method fails with invalid argument for Golang server #1616

Open
anandgmenon opened this issue Mar 17, 2025 · 3 comments

Comments

@anandgmenon
Copy link

anandgmenon commented Mar 17, 2025

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?

@anandgmenon
Copy link
Author

@Rob-Hague @mus65 any idea on this or any pointers on how we can debug this further?

@Rob-Hague
Copy link
Collaborator

It could be bad input from SSH.NET but given an error talking about memory addresses and nil pointers I would start by looking at the server to see what is causing that

@anandgmenon
Copy link
Author

@Rob-Hague at this point all we see from the server is runtime error: invalid memory address or nil pointer dereference and the server is owned by a third party and we have no control over it. Is it possible to add some logging in SSH.NET to figure out if its a bad input ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants