SVN 187 Probable Overflow error in PacketWriter.cs
I'm fairly certain that I just discovered a bug in PacketWriter.cs. I'm no expert on this stuff, by any means, so some peer review would be greatly appreciated.
Regardless, the AccountLoginAck() method of the Server.Network.AccountLoginAck class is:
Note the highlighted line. It's calling m_Stream.Write (I changed all of the "m_"'s to "this", simply because I've always hated hungarian notation with a real passion) with the si.TimeZone variable cast to an sbyte. The problem is that System.MemoryStream.WriteByte takes an unsigned byte as it's parameter. Therefore, when the computer running the server is in a TimeZone with a negative value (I'm currently living in the Pacific time zone, which is -7 right now) it's a problem.
Of course, I turned on arithmetic overflow exceptions in my build, so this shouldn't really be an issue for most people... but, that's why this is in the Core Modifications forum rather than the Server forum.
The best (immediate) solution that I can think of is to use Math.Abs like:
but that's obviously a cludge...
I'm fairly certain that I just discovered a bug in PacketWriter.cs. I'm no expert on this stuff, by any means, so some peer review would be greatly appreciated.
Regardless, the AccountLoginAck() method of the Server.Network.AccountLoginAck class is:
Code:
public AccountLoginAck( ServerInfo[] info ) : base( 0xA8 )
{
this.EnsureCapacity( 6 + (info.Length * 40) );
thisStream.Write( (byte) 0x5D ); // Unknown
thisStream.Write( (ushort) info.Length );
for ( int i = 0; i < info.Length; ++i )
{
ServerInfo si = info[i];
thisStream.Write( (ushort) i );
thisStream.WriteAsciiFixed( si.Name, 32 );
thisStream.Write( (byte) si.FullPercent );
[COLOR="Red"] thisStream.Write( (sbyte) si.TimeZone );[/COLOR]
thisStream.Write( (int) Utility.GetAddressValue( si.Address.Address ) );
}
}
Note the highlighted line. It's calling m_Stream.Write (I changed all of the "m_"'s to "this", simply because I've always hated hungarian notation with a real passion) with the si.TimeZone variable cast to an sbyte. The problem is that System.MemoryStream.WriteByte takes an unsigned byte as it's parameter. Therefore, when the computer running the server is in a TimeZone with a negative value (I'm currently living in the Pacific time zone, which is -7 right now) it's a problem.
Of course, I turned on arithmetic overflow exceptions in my build, so this shouldn't really be an issue for most people... but, that's why this is in the Core Modifications forum rather than the Server forum.
The best (immediate) solution that I can think of is to use Math.Abs like:
Code:
thisStream.Write( (byte) Math.Abs(si.TimeZone) );