You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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));
}
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.
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
The text was updated successfully, but these errors were encountered: