1

Closed

OverflowException on empty server response

description

Hello,

I'm trying to connect to OS X Mountain Lion from a Windows Phone 7.5 application using a SFTP client implemented using your library (version 2013.4.7), and upon sftpclient.connect, after a few seconds of it apparently waiting for something, it crashes with OverflowException. Debugging in the source code the OverflowException is thrown in line 88 of Session.SilverlightShared.cs:
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
At this point buffer.Count = 0, so buffer.Count -1 is actually -1.

Looking up it did break at:
                //  If zero bytes received then exit
                if (args.BytesTransferred == 0)
                    break;
However in the subsequent tests that case doesn't seem handled:
            if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
            {
                response = string.Empty;
            }
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
            else
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
So I added a simple line as follows and now I do get the "Server string is null or empty" exception as expected:
            if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
            {
                response = string.Empty;
            }
            else if (buffer.Count == 0) response = string.Empty; // <-- this line right here
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
            else
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
Closed Apr 6 at 2:56 PM by drieseng

comments

drieseng wrote Feb 16 at 5:58 AM

This issue was fixed by Oleg on July 10th 2013 (changeset 28764), and will be part of the next release.

** Closed by drieseng 15/02/2014 11:38

drieseng wrote Feb 16 at 5:59 AM

Let's keep the issue open (with status Resolved) until we release a version that contains this fix.