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

Issue with reading of data [DNET292] #303

Closed
firebird-automations opened this issue Jan 28, 2010 · 2 comments
Closed

Issue with reading of data [DNET292] #303

firebird-automations opened this issue Jan 28, 2010 · 2 comments

Comments

@firebird-automations
Copy link

Submitted by: Russell Rose (russ3ell)

The issue occurs within in XdrStream.cs and is specifically related to the routines ReadInt32, ReadInt64 and ReadBytes(int count). None of these routines compare the no of bytes read within the Read routine with the number of bytes requested. This means that potentially the number of bytes requested do not match the number of bytes delievered. I actually hit this issue during my testing.

When speaking to Jiri, he suggested that I try the ReadByte() mechanism, but as this can also return a -1, this return would also have to be tested to ensure reliability. Given below are my suggested changes that seem to sort out my problem

public byte[] ReadBytes(int count)
{
return this.ReadOpaque(count, false);
}

public byte[] ReadOpaque(int length)
{
return this.ReadOpaque(length, true);
}

public byte[] ReadOpaque(int length,Boolean pad)
{
byte[] buffer = new byte[length];
int readed = 0;
if (length > 0)
{
while (readed < length)
{
readed += this.Read(buffer, readed, length - readed);
}
// Add padding if required
int padLength = ((4 - length) & 3);
if (padLength > 0 && pad)
{
this.Read(Pad, 0, padLength);
}
}
return buffer;
}

public int ReadInt32()
{
return IPAddress.HostToNetworkOrder(BitConverter.ToInt32(ReadOpaque(4,false), 0));
}

public long ReadInt64()
{
return IPAddress.HostToNetworkOrder(BitConverter.ToInt64(ReadOpaque(8,false), 0));
}

Commits: c2e2288

@firebird-automations
Copy link
Author

Commented by: @cincuranet

The -1 in ReadByte is returned if end of stream is reached. Then any other reading has no sense. Also we need to check whether the Read method returned > 0, else also the EOF. But adding this check is pretty easy.

I'm running the tests right now, so soon it'll be available in SVN.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 2.5.2 [ 10370 ]

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

No branches or pull requests

2 participants